How jQuery gets and sets form elements

  • 2020-03-30 01:45:56
  • OfStack

JQuery provides the val () method, which allows you to quickly get and set the values of the form's text boxes, radio buttons, and radio buttons.
Use val() with no arguments to get the value of the element
Given an argument with val(), you assign a value to an element

As follows:


//Get the value
alert($("input#mytextbox").val());
alert($("select#mylist").val());
alert($("input#myradio").val());
//Set the value
$("input#mytextbox").val("61dh");
$("select#mylist").val(" The first column ");
$("input#myradio").val(2);


Related articles: