jQuery는 라디오 값을 가져오고, jquery는 폼 요소 값을 가져옵니다.

jQuery  Radio   Value :

1. $("input[name='radio_name'][checked]").val();  //     Radio Value 
2. $("#text_id").focus(function(){//code...});  //      text_id       
3. $("#text_id").blur(function(){//code...});  //      text_id       
4. $("#text_id").select();  //     Vlaue      
5. $("input[name='radio_name'][value='  Radio Value ']").attr("checked",true);   jQuery  CheckBox   Value

    :
1. $("input[name='checkbox_name'][checked]");  //     CheckBox            Value ,     
2. $($("input[name='checkbox_name'][checked]")).each(function(){arrChk+=this.value + ',';});  //     CheckBox        Value 
3. $("#checkbox_id").attr("checked");  //    CheckBox   (      ,  true/false)
4. $("#checkbox_id").attr("checked",true);  //    CheckBox      (checked=true)
5. $("#checkbox_id").attr("checked",false);  //    CheckBox       (checked=false)
6. $("input[name='checkbox_name']").attr("checked",$("#checkbox_id").attr("checked")); 

7. $("#text_id").val().split(",");  // Text Value  ','         

 

jQuery--checkbox  /    

 JavaScript       checkbox  /    ,     ,            。   jQuery      ,      ,  !
<input type="checkbox" name="chk_list" id="chk_list_1" value="1" />1<br />
<input type="checkbox" name="chk_list" id="chk_list_2" value="2" />2<br />
<input type="checkbox" name="chk_list" id="chk_list_3" value="3" />3<br />
<input type="checkbox" name="chk_list" id="chk_list_4" value="4" />4<br />
<input type="checkbox" name="chk_all" id="chk_all" />  /    
<script type="text/javascript">

$("#chk_all").click(function() {  $("input[name='chk_list']").attr("checked",$(this).attr("checked"));});
</script>


jQuery.attr    /        , :

$("input[name='chk_list']").attr("checked");     //    name 'chk_list'     (    )

$("input[name='chk_list']").attr("checked",true);      //    name 'chk_list'   checked true

  :

$("#img_1").attr("src","test.jpg");    //  ID img_1 <img>src   'test.jpg'
$("#img_1").attr("src");     //  ID img_1 <img>src 

 

                 checkbox value :
<script type="text/javascript"> //     name 'chk_list'    checkbox(  )   

 var arrChk=$("input[name='chk_list]:checked");    //      checkbox value 

    for (var i=0;i<arrChk.length;i++){     alert(arrChk[i].value); }
</script>

<script type="text/javascript">

   var arrChk=$("input[name='chk_list']:checked"); $(arrChk).each(function() {   window.alert(this.value);  }); });</script>

 

jQuery- Select     [   ]

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 :

     ,Select     Option
     Select         Option
      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

 

JQUERY  text,areatext,radio,checkbox,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          
                $("<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'>1111</option><optionvalue='2'>2222</option>").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();//     

jQuery  select    

    。

    jQuery("#select1").val();       ,

  jQuery("#select1").text();       。

      ,     :

jQuery("#select1  option:selected").text();

 

  select  option       (jquery  )

 

  select,     select           select ,              option     .
          jquery  ,               .
     (listtolist.js):

Js  

/** 

fromid: list id. 

toid:  list id. 

moveOrAppend  ("move"   "append"): 

move --  list    option   . list    option     list ,   list      option   . 

append --  list    option    . list    option     list   ,   list      option   . 

 

isAll  (true  false):          

*/  

jQuery.listTolist = function(fromid,toid,moveOrAppend,isAll) {  

    if(moveOrAppend.toLowerCase() == "move") {  //    

        if(isAll == true) { //      

            $("#"+fromid+" option").each(function() {  

                //  list  option     list,   list    option       .  

                $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  

            });  

            $("#"+fromid).empty();  //   list  

        }  

        else if(isAll == false) {  

            $("#"+fromid+" option:selected").each(function() {  

                //  list  option     list,   list    option       .  

                $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  

                //  list      option     ,    list ,    .  

                if($("#"+fromid+" option[value="+$(this).val()+"]").length > 0) {  

                    $("#"+fromid).get(0)  

                    .removeChild($("#"+fromid+" option[value="+$(this).val()+"]").get(0));  

                }  

            });  

        }  

    }  

    else if(moveOrAppend.toLowerCase() == "append") {  

        if(isAll == true) {  

            $("#"+fromid+" option").each(function() {  

                $("<option></option>")  

                .val($(this).val())  

                .text($(this).text())  

                .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  

            });  

        }  

        else if(isAll == false) {  

            $("#"+fromid+" option:selected").each(function() {  

                $("<option></option>")  

                .val($(this).val())  

                .text($(this).text())  

                .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  

            });  

        }  

    }  

};  

/** 

      ("move"). 

        list    option   list    , list  option    . 

 

isAll  (true  false):          

*/  

jQuery.list2list = function(fromid,toid,isAll) {  

    if(isAll == true) {  

        $("#"+fromid+" option").each(function() {  

            $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  

        });  

    }  

    else if(isAll == false) {  

        $("#"+fromid+" option:selected").each(function() {  

            $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  

        });  

    }  

};  

<script type="text/javascript">
   jQuery(function($)    
{         //  select         
$("#submitBut").click(function(){     //        
    //var strText = $("select[@name=fselect] option[@selected]").text();    
     // var strValue = $("select[@name=fselect] option[@selected]").val();    
      //alert(strText + ":" + strValue);    
       //    t3    
   $("#fselect").attr("value", "t3");     //        
   $('#fselect')[0].selectedIndex = 1;   
     alert($("#fselect")[0].length);    
   });    
      //select                  
   $("#fselect").change(function(){      //          
   //alert($(this)[0].length);    
//               var strText = $(this).text();    
      //            var strValue = $(this).val();    
 //alert(strText + ":" + strValue);    
      //    t3     //         
   //$(this)[0].selectedIndex = 3;       //$(this).attr("value", "t3");       / /$("#fselect")[0].options[2].selected = true;    
      //             
   //     2       
   var nCurrent = $(this)[0].selectedIndex;    
      alert($("#fselect")[0].options[nCurrent].text);    
      alert(strValue);    
   });    
       
   //  select    
   $("#add").click(function(){    
     var nLength = $("#fselect")[0].length;    
     var option = document.createElement("option");;    
     option.text = "Text" + (nLength+1).toString();    
     option.value = "t" + (nLength+1).toString();    
     $("#fselect")[0].options.add(option);    
     //$("#fselect").addOption("Text" + (nLength+1).toString(), "t" + (nLength+1).toString(), true);    
   });            //  select    
   $("#clear").click(function(){    
     $("#fselect").empty();    
   });       //        
$("#remove").click(function(){    
     var index = $("#fselect")[0].selectedIndex;    
     //$("#fselect")[0].remove(index);    
     $("#fselect")[0].options[index] = null;    
   });    
})    
</script>

    select        :
  select       
var item = $("select[@name= stsoft] option[@selected]").text();
select               
$('#stsoft')[0].selectedIndex = 1;
  value 
$('#stsoft').val();
  value=1         
$("#stsoft").attr("value",“1”);
$('#stsoft').val(“1”);

Js  

     /** 
     fromid: list id. 
     toid:  list id. 
     moveOrAppend  ("move"   "append"): 
     move --  list    option   . list    option     list ,   list      option   . 
     append --  list    option    . list    option     list   ,   list      option   . 
      
     isAll  (true  false):          
     */  
 jQuery.listTolist = function(fromid,toid,moveOrAppend,isAll) {  
     if(moveOrAppend.toLowerCase() == "move") {  //    
         if(isAll == true) { //      
             $("#"+fromid+" option").each(function() {  
                 //  list  option     list,   list    option       .  
                 $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  
             });  
             $("#"+fromid).empty();  //   list  
         }  
         else if(isAll == false) {  
             $("#"+fromid+" option:selected").each(function() {  
                 //  list  option     list,   list    option       .  
                 $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  
                 //  list      option     ,    list ,    .  
                 if($("#"+fromid+" option[value="+$(this).val()+"]").length >  {  
                     $("#"+fromid).get(  
                     .removeChild($("#"+fromid+" option[value="+$(this).val()+"]").get();  
                 }  
             });  
         }  
     }  
     else if(moveOrAppend.toLowerCase() == "append") {  
         if(isAll == true) {  
             $("#"+fromid+" option").each(function() {  
                 $("<option></option>")  
                 .val($(this).val())  
                 .text($(this).text())  
                 .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  
             });  
         }  
         else if(isAll == false) {  
             $("#"+fromid+" option:selected").each(function() {  
                 $("<option></option>")  
                 .val($(this).val())  
                 .text($(this).text())  
                 .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  
             });  
         }  
     }  
 };   /** 
       ("move"). 
         list    option   list    , list  option    . 
 isAll  (true  false):          
 jQuery.listist = function(fromid,toid,isAll) {  
     if(isAll == true) {  
         $("#"+fromid+" option").each(function() {  
             $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  
         });  
     }  
     else if(isAll == false) {  
         $("#"+fromid+" option:selected").each(function() {  
             $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));  
         });  
     }  
 };
   :http://www.cnblogs.com/tangself/archive/2010/04/14/1711684.html

좋은 웹페이지 즐겨찾기