Home > Web Front-end > JS Tutorial > Jquery's value collection and assignment examples for basic controls_jquery

Jquery's value collection and assignment examples for basic controls_jquery

WBOY
Release: 2016-05-16 16:47:02
Original
1095 people have browsed it

TEXTBOX:

var str =$("#txt").val();

$("#txt").val(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(Value);

/*Get the value of the radio button*/

var valradio =$("input[@type=radio][@checked] ").val();

/*Get the value of a set 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();

//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 the

radio group has been selected 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 Then 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;

radio radio selection group The second element is the currently selected value

$('input[@name=items]').get(1).checked= true;

//Reset form

$("form").each(function(){

.reset();

});

The following is the path to set img

$("#img1").attr("src","Imges/test.jpg");

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