我有很多这样的输入域
<input type="radio" name="name" id="name" onchange="enableTxt()" />
当我点击这个单选按钮时,我想要捕获无线输入的id。我正在使用下面的代码
function enableTxt() {
var id = $(this).attr("id");
alert(id);
}
我得到了这个错误
a.attributes is undefined
发布于 2010-12-08 14:44:43
HTML:
<input type="radio" name="name" id="name" onchange="enableTxt(this)" />
JS:
function enableTxt(elem) {
var id = $(elem).attr("id");
alert(id);
}
发布于 2016-09-22 11:41:30
这个html
<button class="destroy" id="123">
The jQuery
$('button.destroy').on('click', function(e){
e.preventDefault();
console.log(this.id);
发布于 2010-12-08 14:57:50
您可以只从HTML传递ID
<input type="radio" name="name" id="name" onchange="enableTxt($(this).attr('id'))" />
function enableTxt(id)
{
alert(id);
}
https://stackoverflow.com/questions/4384829
复制相似问题