Home > Web Front-end > JS Tutorial > A simple example of Jquery operating radio_jquery

A simple example of Jquery operating radio_jquery

WBOY
Release: 2016-05-16 17:05:21
Original
928 people have browsed it

Jquery plug-in tutorial
Jquery learning
PHP learning



In the above html code, if you are careful, you should be able to find that the name attributes of three radios and the name attribute of one text are all "study"

Copy code The code is as follows:

$(function(){
$('#tijiao').click(function(){
if ($ ("input:[name=study]:radio:checked").length == 0){
alert("Please select the knowledge you want to learn");
return false;
}
var study = $("input:[name=study]:radio:checked").val();
alert("Thank you! You selected " study);
})
$ ("#set_jqeury_study").click(function(){
var $button = $(this);
$("input:[name=study]:radio").each(function(){
if (this.value == $button.attr('title')){
this.checked=true;
}
})
})
$("# view_input_text").click(function(){
alert($("input[name=study]:text").val());
})
})

$("input:[name=study]:radio:checked") This code obtains all the jquery objects of the radio whose name attribute is "study" and has been selected, by judging whether its length is equal to 0 , you can know whether one of the radio options is selected. $("input[name=study]:text") This code obtains the jquery object of the text input box whose name attribute is "study".
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