회전: jQuery 선택 한 Text 와 Value 가 져 오기

9469 단어 jquery

    :http://blog.chinaunix.net/u3/111819/showart_2197944.html

jQuery  Select   Text Value:
    :
1. $("#select_id").change(function(){//code...});   // Select    ,          
2. var checkText=$("#select_id").find("option:selected").text();  //  Select   Text
3. var checkValue=$("#select_id").val();  //  Select   Value
4. var checkIndex=$("#select_id ").get(0).selectedIndex;  //  Select      
5. var maxIndex=$("#select_id option:last").attr("index");  //  Select       
jQuery  Select    Text Value:
    :
1. $("#select_id ").get(0).selectedIndex=1;  //  Select    1    
2. $("#select_id ").val(4);   //   Select Value  4    
3. $("#select_id option[text='jQuery']").attr("selected", true);   //  Select Text  jQuery    
jQuery  /  Select Option :
    :
1. $("#select_id").append("<option value='Value'>Text</option>");  // Select    Option(   )
2. $("#select_id").prepend("<option value='0'>   </option>");  // Select    Option(     )
3. $("#select_id option:last").remove();  //  Select      Option(    )
4. $("#select_id option[index='0']").remove();  //  Select     0 Option(   )
5. $("#select_id option[value='3']").remove();  //  Select Value='3' Option
5. $("#select_id option[text='4']").remove();  //  Select Text='4' Option  http://www.cnblogs.com/SAL2928/archive/2008/10/28/1321285.html

jquery radio  ,checkbox  ,select  ,radio  ,checkbox  ,select  ,     
     radio       
var item = $('input[@name=items][@checked]').val(); 
   select        
var item = $("select[@name=items] option[@selected]").text(); 
select                
$('#select_id')[0].selectedIndex = 1; 
radio                
$('input[@name=items]').get(1).checked = true; 

   : 

   ,    :$("#txt").attr("value"); 
    checkbox:$("#checkbox_id").attr("value"); 
   radio:   $("input[@type=radio][@checked]").val(); 
   select: $('#sel').val(); 

      : 
   ,    :$("#txt").attr("value",'');//     
$("#txt").attr("value",'11');//     

   checkbox: $("#chk1").attr("checked",'');//    
$("#chk2").attr("checked",true);//   
if($("#chk1").attr('checked')==undefined) //         

    radio:    $("input[@type=radio]").attr("checked",'2');//  value=2          
    select:   $("#sel").attr("value",'-sel3');//  value=-sel3          
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//      option 
$("#sel").empty();//     

----------------------------------------------------------------------------------------------------

 

//  option   、  option
function changeShipMethod(shipping){
var len = $("select[@name=ISHIPTYPE] option").length
if(shipping.value != "CA"){
$("select[@name=ISHIPTYPE] option").each(function(){
if($(this).val() == 111){
$(this).remove();
}
});
}else{
$("<option value='111'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]"));
}
}


//          

$(#testSelect option:selected').text();
 $("#testSelect").find('option:selected').text();
 $("#testSelect").val();
//////////////////////////////////////////////////////////////////
           :
1,   :

var cc1 = $(".formc select[@name='country'] option[@selected]").text(); //             (       )
var cc2 = $('.formc select[@name="country"]').val(); //            
var cc3 = $('.formc select[@name="country"]').attr("id"); //           ID   
$("#select").empty();//      //$("#select").html('');
$("<option value='1'>1111</option>").appendTo("#select")//      option

      :
1.select[@name='country'] option[@selected]     name   ,
        'country'  select        selected    option   ;
     @              。

2,   :
$("input[@type=radio][@checked]").val(); //            (        )
$("input[@type=radio][@value=2]").attr("checked",'checked'); //     value=2      .(        )

3,   :
$("input[@type=checkbox][@checked]").val(); //              
$("input[@type=checkbox][@checked]").each(function() { //             ,        
alert($(this).val());
});

$("#chk1").attr("checked",'');//   
$("#chk2").attr("checked",true);//   
if($("#chk1").attr('checked')==undefined){} //        


  jquery        .       .

<script src="jquery-1.2.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#selectTest").change(function()
{
//alert("Hello");
//alert($("#selectTest").attr("name"));
//$("a").attr("href","xx.html");
//window.location.href="xx.html";
//alert($("#selectTest").val());
alert($("#selectTest option[@selected]").text());
$("#selectTest").attr("value", "2");

});
});
</script>


<a href="#">aaass</a>

<!--   -->
<select id="selectTest" name="selectTest">
<option value="1">11</option>
<option value="2">22</option>
<option value="3">33</option>
<option value="4">44</option>
<option value="5">55</option>
<option value="6">66</option>
</select>
jquery radio  ,checkbox  ,select  ,radio  ,checkbox  ,select  ,        radio       
var item = $('input[@name=items][@checked]').val();
  select        
var item = $("select[@name=items] option[@selected]").text();
select                
$('#select_id')[0].selectedIndex = 1;
radio                
$('input[@name=items]').get(1).checked = true;
   :
    ,    :$("#txt").attr("value");
    checkbox:$("#checkbox_id").attr("value");
   radio: $("input[@type=radio][@checked]").val();
   select: $('#sel').val();
       :
   ,    :$("#txt").attr("value",'');//    
$("#txt").attr("value",'11');//     
   checkbox: $("#chk1").attr("checked",'');//   
$("#chk2").attr("checked",true);//   
if($("#chk1").attr('checked')==undefined) //        
   radio: $("input[@type=radio]").attr("checked",'2');//  value=2         
    select: $("#sel").attr("value",'-sel3');//  value=-sel3         
$("<optionvalue='1'& gt;1111</option><optionvalue='2'>2222</option& gt;").appendTo("#sel")//      option
$("#sel").empty();//      

    radio      
var item = $('input[@name=items][@checked]').val();
  select       
var item = $("select[@name=items] option[@selected]").text();
select                
$('#select_id')[0].selectedIndex = 1;
radio               
$('input[@name=items]').get(1).checked = true;
   :
   ,    :$("#txt").attr("value");
    checkbox:$("#checkbox_id").attr("value");
   radio: $("input[@type=radio][@checked]").val();
   select: $('#sel').val();
       :
   ,    :$("#txt").attr("value",'');//    
$("#txt").attr("value",'11');//     
   checkbox: $("#chk1").attr("checked",'');//   
$("#chk2").attr("checked",true);//   
if($("#chk1").attr('checked')==undefined) //        
   radio: $("input[@type=radio]").attr("checked",'2');//  value=2         
    select: $("#sel").attr("value",'-sel3');//  value=-sel3         
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//      option
$("#sel").empty();//      
 




좋은 웹페이지 즐겨찾기