Home > Article > Web Front-end > How to solve the problem of radio dynamic control selection failure in jquery
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'));
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);
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!