我一直试图通过ONCLICK BUTTONS擦除textarea中添加的最后一个输入,但似乎没有擦除最后一个输入,而是擦除了所有的onclick输入。
注意,按钮应该是onclick,因为它变量动态变化。
<html>
<textarea id="Content" name="Content"></textarea>
<button class="AddTo" value="a">a</button>
<button class="AddTo" value="b">b</button>
<button class="AddTo" value="c">c</button>
<button class="Backspace" value="">backspace</button>
<button type="button" onclick="myFunctionY1();" class="list1" style="width:80px; background-color:red;" id="Y1">Y1</button>
<button type="button" onclick="myFunctionY2();" class="list1" style="width:80px; background-color:red;" id="Y2">Y2</button>
<script>
function myFunctionY1() {
document.getElementsByName("Content")[0].value += "Hello!";
}
function myFunctionY2() {
document.getElementsByName("Content")[0].value += "Hi!";
}
</script>
</html>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.js"> </script>
<script>
var values = [];
$(function () {
$('.AddTo').on('click', function () {
values.push($(this).val());
$('#Content').val(values.join(" "));
});
$('.Backspace').on('click', function () {
values.pop();
$('#Content').val(values.join(" "));
});
});
</script>
答案 0 :(得分:0)
做到这一点:
<html>
<textarea id="Content" name="Content"></textarea>
<button class="AddTo" value="a">a</button>
<button class="AddTo" value="b">b</button>
<button class="AddTo" value="c">c</button>
<button class="Backspace" value="">backspace</button>
<button type="button" class="list1" value="Hello!" style="width:80px; background-color:red;" id="Y1">Y1</button>
<button type="button" class="list1" value="Hi!" style="width:80px; background-color:red;" id="Y2">Y2</button>
</html>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.js"> </script>
<script>
var values = [];
$(function () {
$('#Y1').attr("value", "foo");
$('#Y2').attr("value", "foo2");
$('.AddTo').on('click', function () {
values.push($(this).val());
$('#Content').val(values.join(" "));
});
$('.Backspace').on('click', function () {
values.pop();
$('#Content').val(values.join(" "));
});
$('.list1').on('click', function () {
values.push($(this).val());
$('#Content').val(values.join(" "));
});
});
</script>
&#13;