我有 2 个文本字段和 2 个按钮调用相同的函数。
<input type="text" id="value1"/>
<input type="button" value="Get value" id="getvalue"/><br>
<input type="text" id="value2"/>
<input type="button" value="Get value" id="getvalue"/><br>
$('#getvalue').click(function(){
recording one value at a time
});
如何记录同一函数中的每个单独值。 非常欢迎任何建议。
谢谢。
最佳答案
ID 应该是唯一的。
为什么不使用这样的代码。
<input type="text" id="value1"/>
<input type="button" value="Get value" class="getvalue" id="btn1" /><br>
<input type="text" id="value2"/>
<input type="button" value="Get value" class="getvalue" id="btn2"/><br>
$('input.getvalue').click(function(){
if (this.id == "btn1") {
}
if (this.id == "btn2") {
}
});
关于javascript - 如何区分调用相同jquery函数的2个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24178051/