我正在使用以下代码来提醒当前元素的id.
<input type="text" id="desc" name="txtTitle" onclick="fun()">
Run Code Online (Sandbox Code Playgroud)
jQuery的:
function fun () {
var currentId = $(this).attr('id');
alert(currentId);
}
Run Code Online (Sandbox Code Playgroud)
为什么警告"未定义"?我尝试过:
var currentId =$('element').attr('id');
// and
alert($(this).id);
// and
alert(this.id);
Run Code Online (Sandbox Code Playgroud)
但它提醒 undefined
jquery ×1