Home > Web Front-end > JS Tutorial > body text

How to solve the problem of radio dynamic control selection failure in jquery

亚连
Release: 2018-06-04 10:48:55
Original
1755 people have browsed it

Below I will share with you a solution to the jquery radio dynamic control selection failure problem. It has a good reference value and I hope it will be helpful to everyone.

Gender selection Male and female Usually radio is used. When modifying customer information, the radio needs to be selected based on the information.

The initial code approach is

console.log($(':radio[value='+data[2]+']').attr('checked'));
Copy after login

But after testing, there were problems and I selected them separately. Men and women will become invalid in the future.

After searching for information, it turned out that it was a jQuery version problem. Attr was modified in different versions

**如果你的jQuery库的版本是1.6以下的,使用attr方法
如果你的jquery库的版本是1.6(含1.6)以上的,使用prop方法**
$(':radio[value='+data[2]+']').prop('checked',true);
Copy after login

This completely solved the test Also completely normal.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to operate custom instructions in Vue to implement the checkbox selection function

In Node.js How to use the DNS module in (detailed tutorial)

#Request interceptors in the Vue network, what should be done specifically?

The above is the detailed content of How to solve the problem of radio dynamic control selection failure in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!