Home > Web Front-end > JS Tutorial > How to solve the problem of radio dynamic control selection failure

How to solve the problem of radio dynamic control selection failure

php中世界最好的语言
Release: 2018-03-14 16:18:46
Original
2439 people have browsed it

This time I will show you how to solve the failure of radio dynamic control selection. What are the precautions to solve the failure of radio dynamic control selection? The following is a practical case, let’s take a look. take a look.

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 method is

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

But there is a problem after testing. After selecting men and women separately, it will become invalid.

After searching for information, it turned out to be a version problem with

jQuery. Attr has been modified in different versions

**If your jQuery library version is below 1.6 , use the attr method

If your jquery library version is 1.6 (including 1.6) or above, use the prop method**
$(':radio[value='+data[2]+']') .prop('checked',true);

This completely solves the problem and the test is completely normal.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website

Other related articles!

Recommended reading:

How to implement the toggle method in jQuery

jQuery+JSONWhat is required for cross-domain P Realize

How to realize the jquery carriage return login effect



The above is the detailed content of How to solve the problem of radio dynamic control selection failure. 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