Radiobutton,input,checkbox value Assignment in jquery to implement code _php techniques

Source: Internet
Author: User

1, jquery access to a single select group radio
$ ("Input[name= ' name ']:checked"). Val ();

2. jquery gets the next value of RadioButton
$ ("Input[name= ' name ']:checked"). Next (). Text ()
$ ("Input[name= ' name ']:checked"). Val ()

3, jquery get the value of input
$ (' #id '). Val ()

4. jquery to judge multiple-selection box checkbox
$ ("#id: CheckBox"). attr ("checked")
Takes a value of $ ("#id"). attr ("value");
The assignment is directly to the value in the text (), Val ()

How does jquery get the Text,areatext,radio,checkbox,select value?
$ ("input"). Val ();
$ ("textarea"). Text ();
$ ("select"). Val ();

Control form elements:
text box, text area: $ ("#txt"). attr ("Value", "");/empty content
$ ("#txt"). attr ("value", ' 11 ');//fill content
Multi-Marquee checkbox: $ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//judge whether it has been ticked

Single-select group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 project is currently selected

Dropdown box Select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item as current selection
$ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). Appendto ("#sel")// Option to add a drop-down box
$ ("#sel"). empty ();//Empty Drop-down box

JQuery gets and sets the value of the Select Drop-down Box article Category:. NET programming

Get select:
Gets the text selected by select:
$ ("#ddlRegType"). Find ("option:selected"). Text ();

Gets the value selected by select:
$ ("#ddlRegType"). Val ();

Gets the index selected by select:
$ ("#ddlRegType"). Get (0). SelectedIndex;

Set Select:
Set the index selected by select:
$ ("#ddlRegType"). Get (0). Selectedindex=index;//index is the index value

Set the value selected by select:
$ ("#ddlRegType"). attr ("value", "Normal");
$ ("#ddlRegType"). Val ("Normal");
$ ("#ddlRegType"). Get (0). value = value;

Set selected text for select:
var count=$ ("#ddlRegType option"). Length;
for (Var i=0;i<count;i++)
{if ($ ("#ddlRegType"). Get (0). Options[i].text = text)
{
$ ("#ddlRegType"). Get (0). options[i].selected = true;
Break
}
}
$ ("#select_id option[text= ' jQuery ']"). attr ("selected", true);

To set the SELECT option item:
$ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Add an option
$ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option before
$ ("#select_id option:last"). Remove (); Delete the maximum index value option
$ ("#select_id option[index= ']"). Remove ()//delete option with index value of 0
$ ("#select_id option[value= ' 3 ']"). Remove (); Delete option with a value of 3
$ ("#select_id option[text= ' 4 ']"). Remove (); Delete option with text value of 4

Empty Select:
$ ("#ddlRegType"). empty ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.