我正在尝试做一个在单击他的 ID 和变量时递增的按钮。我能够在 StackOverflow 上找到一些增加输入字段值的代码,但我不知道从那里更改它。
这是标记:
<input type="text" name="qty" value="0" />
<p id="inc">Increase</p>
<p id="dec">Decrease</p>
和 jQuery
<script>
$(document).ready(function()
{
$(function()
{
$("#inc").click(function()
{
$(":text[name='qty']").val(Number($(":text[name='qty']").val()) + 1);
$('#inc').addClass (Number + 1); // this one does not work
var incrementVar = (Number + 1); // this one also does not work
});
$("#dec").click(function()
{
$(":text[name='qty']").val(Number($(":text[name='qty']").val()) - 1);
});
});
});
</script>
这确实增加了输入中的 val,但我不能让它增加 $('#inc') 类和 var incrementVar。
我该怎么办?谢谢