当我第二次单击“输入文本按钮”时,如何删除“单击时在textarea中输入此文本”文本?没有javascript可以吗?
<textarea name=\"text\" rows=\"10\" cols=\"50\">" . htmlspecialchars($arr["text"]) . "</textarea>
<INPUT TYPE="button" NAME="insert" VALUE="Input text button" onClick="this.form.text.value=this.form.text.value.concat('Input this text in textarea on click');">
答案 0 :(得分:0)
<form>
<textarea name="text" id="text" rows="10" cols="50"></textarea>
<input type="button" name="insert" id="insert" value="Input text button" />
</form>
<script type="text/javascript">
document.getElementById('insert').onclick = function() {
var txt = 'Input this text in textarea on click',
area = document.getElementById('text');
area.value = area.value.indexOf(txt) != -1 ? area.value.replace(txt, '') : area.value + txt;
}
</script>