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"
$(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".
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