Jquery knowledge point three jquery form object operation_jquery
WBOY
Release: 2016-05-16 18:12:02
Original
916 people have browsed it
In Jquery, if these three functions have parameters, they are assignment operations. If there are no parameters, they are value acquisition operations. Among them, val() is a very important method, and its related form objects such as: input system labels, select, textarea etc. are all tag elements used to interact with the server, so you need to understand this val(); For assignment operations of radio, checkbox, and select:
$("input[name=a]").val(["Entertainment 1"]) ; $("input[type=checkbox]").val(["Basketball", "Game"]); $("select").val(["Basketball", "Game"] ; [], if there are multiple values, separate them with commas; Assign a value to the select and obtain the select through the label selector.
For the value operations of radio, checkbox, and select:
declares an s The variable is used to receive the selected value of the radio with name=a. It can also be written as var s=$(":radio:checked").val(). :radio can be understood as the input element of type=radio, which is an attribute. A simplified way of writing a selector; Get the selected value of the checkbox. Because the checkbox is a multi-select box, each selected item needs to be processed with each. It can also be written according to the attribute selector: $(" input[type=checkbox]:checked"); For select, when the attribute multiple ="multiple", multiple selections can be made. Here, each is also used for traversal processing;
Summary: For input-based tag elements, we can use the attribute selector to obtain: $("input[type=checkbox]"), or in a concise way: $(":checkbox"), similar ones: : radio, :submit, :image, :reset, :button, :file, :hidden, :password, :text; $(":input")Select all
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