How jQuery evaluates and assigns HTML elements

  • 2020-03-29 23:53:37
  • OfStack

Var STR = $('# TXT ').val(); $(' # TXT). Val (" Set Lbl Value "); // text box, text area: $("#text_id").attr("value", "); // empty the content $("#text_id").attr("value",'test'); // fill in the content

TEXTBOX.


var str = $('#txt').val();
$('#txt').val("Set Lbl Value"); 
//Text box, text area:
$("#text_id").attr("value",'');//Empty content
$("#text_id").attr("value",'test');//Fill the 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();
//Multi-checkbox:
$("#chk_id").attr("checked",'');//Leave it unchecked
$("#chk_id").attr("checked",true);//  Check the 
if($("#chk_id").attr('checked')==true) //Determines whether it has been selected

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

//Drop-down box select:
$("#select_id").attr("value",'test');//The item that sets value=test is the currently selected item
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//Add options to the drop-down box
$("#select_id").empty() ; //Clear the drop-down box

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

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


Related articles: