Home >Web Front-end >JS Tutorial >jQuery's value acquisition and assignment operation code for form elements_jquery

jQuery's value acquisition and assignment operation code for form elements_jquery

WBOY
WBOYOriginal
2016-05-16 18:06:381085browse

$("#keyword")[0].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 values ​​of a group of radio selected items named (items)*/
var item = $('input[name=items]:checked').val();

/*Get the value of the checkbox*/
var checkboxval = $("#checkbox_id").attr ("value");

/*Get the value of the drop-down list*/
var selectval = $('#select_id').val();

/*Text box, Text area*/
$("#text_id").attr("value",");//Clear the content
$("#text_id").attr("value",'test'); //Fill content

/*Multiple selection box checkbox*/
$("#chk_id").attr("checked",");//Make it unchecked
$( "#chk_id").attr("checked",true);//Check
if($("#chk_id").attr('checked')==true) //Determine whether it has been selected

/*Single selection group radio*/
$("input[type=radio]").attr("checked",'2');//Set the item with value=2 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
$("testtest2").appendTo("#select_id")//Add the option of the drop-down box
$("#select_id").empty();//Clear the drop-down box

/*Get The value of a group of radio selected items named (items)*/
var item = $('input[name=items]:checked').val(); //If not selected, val() = undefined

/*Get the text of the selected item*/
var item = $("select[name=items] option:selected").text();

/*The second element of the select drop-down box is the currently selected value*/
$('#select_id')[0].selectedIndex = 1;

/*The second element of the radio radio selection group The element is the currently selected value*/
$('input[name=items]').get(1).checked = true;

/*Reset the form*/
$(" form").each(function(){
.reset();
});
jQuery takes and assigns values ​​to html elements

Jquery gives basic Control value acquisition and assignment TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //Text box, text area: $( "#text_id").attr("value",'');//Clear the content$("#text_id").attr("value",'test');//Fill the content
Jquery to basic controls Value acquisition and assignment

TEXTBOX:
var str = $('#txt').val();

$('#txt').val("Set Lbl Value");

//Text box, text area:
$("#text_id").attr("value",'');//Clear the content
$("# text_id").attr("value",'test'); // Fill content
LABLE:

var str = $('#lbl').text();

$('#lbl').text("Set Lbl Value");

var valradio = $("input[@type=radio][@checked]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr("value");
var selectval = $('#select_id').val();
//Multiple selection box checkbox:
$("#chk_id").attr("checked",'');//Make it unchecked Check
$("#chk_id").attr("checked",true);// Check
if($("#chk_id").attr('checked')==true) / /Determine whether the
radio group radio has been selected:

$("input[@type=radio]").attr("checked",'2'); //Set value=2 The item is the currently selected item

//Drop-down box select:
$("#select_id").attr("value",'test');//Set the item with value=test as the currently selected item Item
$("").appendTo("#select_id")//Add the option of the drop-down box
$("#select_id").empty (); //Clear the drop-down box

Get the value of a set of radio selected items named (items)
var item = $('input[@name=items][@checked]' ).val();//If not selected, val() = undefined
Get the text of the selected item
var item = $("select[@name=items] option[@selected]" ).text();
The second element of the select drop-down box is the currently selected value
$('#select_id')[0].selectedIndex = 1;
The second element of the radio radio selection group The element is the currently selected value
$('input[@name=items]').get(1).checked = true;

//Reset the form
$("form") .each(function(){
.reset();
}; //Text box, text area: $("#text_id").attr("value",'');//Clear the content $("#text_id").attr("value",'test');/ / Fill content
Jquery’s value collection and assignment to basic controls

TEXTBOX:
var str = $('#txt').val();

$(' #txt').val("Set Lbl Value");

//Text box, text area:
$("#text_id").attr("value",'');/ /Clear content
$("#text_id").attr("value",'test');// Fill content
LABLE:

var str = $('#lbl') .text();

$('#lbl').text("Set Lbl Value");

var valradio = $("input[@type=radio][@checked ]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr ("value");
var selectval = $('#select_id').val();
//Multiple selection box checkbox:
$("#chk_id").attr("checked" ,'');//Make it unchecked
$("#chk_id").attr("checked",true);// Make it checked
if($("#chk_id").attr ('checked')==true) //Determine whether the
radio group radio has been selected:

$("input[@type=radio]").attr("checked",'2 '); //Set the item with value=2 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
$("
testtest2$("#select_id").empty();//Clear the drop-down box

Get the values ​​of a set of radio selected items named (items)
var item = $('input[ @name=items][@checked]').val();//If not selected, val() = undefined
Get the text of the selected item in select
var item = $("select[@ name=items] option[@selected]").text();
The second element of the select drop-down box is the currently selected value
$('#select_id')[0].selectedIndex = 1;
The second element of the radio radio selection group is the currently selected value
$('input[@name=items]').get(1).checked = true;

//Reset Form
$("form").each(function(){
.reset();
});

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