Front-end issues and summary

2018.5.2

The problem of dynamically setting the selected state of radio radio buttons

Probably due to the use of templates, after the radio is clicked, the checked attribute has not changed, but the page display is correct.

So try to use dynamic settings.

code1

$("input[name=TAG_AUTO]").each(function () { $(this).attr("checked", false) });

There is no problem with the code1 code, all selected states are cleared.

code2

$("input[name=TAG_AUTO][value=0]").attr("checked", true) 

But when adding a selected state to the required option, code2 compiles correctly, the result is wrong, and the option is not selected.

Find the reason through Baidu.

Connection address: https://blog.csdn.net/Cc_Rain0624/article/details/73278145

To summarize: attr can be used, but only once, such as when initializing the default selected value of radio.

If the jquery version is above 1.6, please use prop instead of attr control to meet the needs of changing the selected value multiple times.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325170199&siteId=291194637