1. 程式人生 > >js取值和賦值

js取值和賦值

1: 根據class 、 id  取 input 標籤的value 值 。 
                  jQuery     : $(".className").val();  $("#idName").val();
                  javaScript : document.getElementById("idName").value;

2:  根據class 、id 獲取標籤之間的內容:如 <span> 、<lable> 、<div> 。
                 jQuery     : $("#idName").html(); $(".className").html();
                 javaScript : document.getElementById("idName").innerHTML ;
       
3: 獲取<select id='selectId'> <option value='selectValue'>  選中值:
                 jQuery     : $("#selectId").val();

$("#selectId option:selected").val();
                 javaScript : document.getElementById("selectId").value;
       
4: 獲取<img > 的 src 內容 :
                jQuery     : $("#imgId")[0].src;
               javaScript : document.getElementById("imgId").src;
       
5:子介面獲取父介面元素內容:
5.1 (標籤間的內容 ,如 <span> 、<lable> 、<div> )
                       JavaScript : window.parent.document.getElementById("currentPage").innerHTML ;
                       JQuery     : $(window.parent.document).find("#IdName").text();
5.2 (取 input 標籤的value 值) 
                       JavaScript : window.parent.document.getElementById("currentPage").value ;
                       JQuery     : $(window.parent.document).find("#IdName").val();

6:子介面控制父頁面跳轉:

                      window.parent.location.href = “*” ;

7: attr:

$("#test").attr("data-id","");//賦值

$("#test").attr("data-id");//取值