jQuery onClick捕获元素的ID [英] jQuery onClick capture the id of the element

查看:83
本文介绍了jQuery onClick捕获元素的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多这样的输入字段

i have many input fields like this

<input type="radio" name="name" id="name" onchange="enableTxt()" /> 

当我单击此单选按钮时,我想捕获单选输入的ID.我正在使用以下代码

when i click this radio button i wanna capture the id of the radio input. i am using the following code

function enableTxt() {
    var id = $(this).attr("id");
    alert(id);
}

我收到此错误

a.attributes is undefined

推荐答案

HTML:

<input type="radio" name="name" id="name" onchange="enableTxt(this)" /> 

JS:

function enableTxt(elem) {
    var id = $(elem).attr("id");
    alert(id);
}

这篇关于jQuery onClick捕获元素的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆