我正在尝试使用 jQuery 更改按钮的值。
这是我在 html 中的内容:
<button id="choice1">John</button>
这就是我试图改变的值(value):
$(document).ready(function(){
$("#choice1").click(function(){
$(this).val("Mike");
});
});
我什至尝试过 .attr/.prop/.html/.text
而不是 .val
但它们都不起作用。
好吧,如果我想把它改成这样的数组:
var a = new Array(4000)
a[2][1] = "North"
a[2][2] = "South"
a[2][3] = "East"
a[2][4] = "West"
还有函数:
function state1gmg(){
$(document).ready(function(){
$("div#gamestatesdiv").text(state1);
});
$(document).ready(function(){
$("div#questionsdiv").text(q[1]);
});
$(document).ready(function(){
$("#choice1").click(function(){
$(this).html(a[2][1]);
});
});
有什么帮助吗?提前致谢!!
最佳答案
您应该使用 text()
或 html()
而不是 val()
:
$(document).ready(function(){
$("#choice1").click(function(){
$(this).text("Mike");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="choice1">John</button>
关于javascript - 无法使用 jQuery 更改按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45574384/