简体   繁体   中英

How to get individual values of radio buttons that are added dynamically?

I have a drop down that's numbered 1-30. So if I select '2', my radio buttons will appear like this:

<input type="radio" id="yes-sdf-1" name="field[1][sdfradio]" value="Yes" />
<input type="radio" id="no-sdf-1" name="field[1][sdfradio]" value="No" />

<input type="radio" id="yes-sdf-2" name="field[2][sdfradio]" value="Yes" />
<input type="radio" id="no-sdf-2" name="field[2][sdfradio]" value="No" />

How do I get the individual values of the radio buttons because I want to set conditions that will only affect those with the same name.

Here is an example to give you an idea.

Try this:

$('input:radio').click(function(){
    alert($(this).attr('name'));
});

This will return the name of the radio button.

JSFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM