Home  >  Article  >  Web Front-end  >  JQUERY code to get form form value_jquery

JQUERY code to get form form value_jquery

WBOY
WBOYOriginal
2016-05-16 18:22:571461browse

Suppose we have the following page:

.......I won’t write it out here

Let’s look at how to get the various values ​​​​in FORM, etc. etc.;
function get_form_value(){
/*Get the value of TEXT.AREATEXT*/
var textval = $("#text_id").attr("value");//or
var textval = $("#text_id").val();
/*Get the value of the radio button*/
var valradio = $("input[@type=radio][@checked]") .val();
/*Get the value of the checkbox*/
var checkboxval = $("#checkbox_id").attr("value");
/*Get all the items in the drop-down list Value*/
var selectval = $('#select_id').val();
//Get the value in the drop-down list selection, this method works for all drop-down boxes
//This The method works for all drop-down boxes
//If you want to get a certain ID, $('#id>option').each() can

$('select>option') .each(function(){
if($(this).attr('selected')==true)
{
alert($(this).text());
}
})
}
3. Other processing of the form:
//Control form elements:
//Text box, text area:
$("#text_id" ).attr("value",'');//Clear the content
$("#text_id").attr("value",'test');//Fill the content
//Multiple selection boxes checkbox:
$("#chk_id").attr("checked",'');//Unchecked value
$("#chk_id").attr("checked",true);/ /Selected value
if($("#chk_id").attr('checked')==undefined) //Judge whether it has been selected
//Single selection group radio:
$("input [@type=radio]").attr("checked",'10');//Set the radio button with value=10 as the currently selected item
//Drop-down box select:
$("# select_id").attr("value",'test'); //Set the item with value=test as the currently selected item
$(""). appendTo("#select_id")//Add the option of the drop-down box
$("#select_id").empty();//Clear the drop-down box

Statement:
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