JQuery radio (radio button) operation method summary_jquery
May 16, 2016 pm 04:03 PMAs Jquery becomes more and more useful, more and more friends use it. In the Web, due to the high frequency of use of controls such as CheckBox, Radiobutton, and DropDownList, it is related to the operation of these controls in Jquery. Since the version of Jquery is updated very quickly, the way of writing the code has also changed a lot. The following Jquery code is suitable for query1.4 and above.
1. Get the selected value, three methods are available:
$('input:radio:checked').val();
$("input[type='radio']:checked").val();
$("input[name='rd']:checked").val();
2. Set the first Radio as the selected value:
$('input:radio:first').attr('checked', 'checked');
or
$('input:radio:first').attr('checked', 'true');
Note: attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)
3. Set the last Radio as the selected value:
$('input:radio:last').attr('checked', 'checked');
or
$('input:radio:last').attr('checked', 'true');
4. Set any radio as the selected value according to the index value:
$('input:radio').eq(index value).attr('checked', 'true');Index value=0,1,2....
or
$('input:radio').slice(1,2).attr('checked', 'true');
5. Set Radio to the selected value according to the Value value
$("input:radio[value='rd2']").attr('checked','true');
or
$("input[value='rd2']").attr('checked','true');
6. Delete the Radio whose Value is rd2
$("input:radio[value='rd2']").remove();
7. Which Radio to delete
$("input:radio").eq(index value).remove(); index value=0,1,2....
For example, delete the third Radio:$("input:radio").eq(2).remove();
8. Traverse Radio
$('input:radio').each(function(index,domEle){
//Write code
});

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags

60 years in the making: NASA confirms hypothesis on Earth\'s global electric field

How to operate the PC version of Chaoxing Xuetong - How to operate the PC version of Chaoxing Xuetong

Understand the role and application scenarios of eq in jQuery
