jQuery-text()与val()方法区别

<HTML><HEAD>
<script type="text/javascript" src="jquery.js"></script>

<SCRIPT type="text/javascript">$(document).ready(function() {

 $("#ylok").click(function(){
  alert($("p").text()); //将所有的p内容,打印出来   
  alert($("div").text());    
 alert($("span").text());
 alert($("#yltxt").val());//多了#      
 alert($("#yltxt")[0].value);//多了#    
 alert($("#yltxt").attr("value")+"三"); 
 alert($("input[@name='yltext']").val()+"四");
   
  });


});
</SCRIPT>
</HEAD>
<BODY>
 <div class="components-list">
 <input type="checkbox" name="checkbox_name[]" id="checkbox_name_1" />1<br />
 <input type="checkbox" name="checkbox_name[]" id="checkbox_name_2" />2<br />
 <input type="checkbox" name="checkbox_name[]" id="checkbox_name_3" />3<br />
 <input type="checkbox" name="checkbox_name[]" id="checkbox_name_4" />4<br />

 </div>
 <p>Paraparagraph</p>
 <div>1223</div>
 <span>123</span>
 <p>
 
     <select id="test">
       <option value="a">A</option>
       <option value="b">B</option>
       <option value="c" selected>C</option>
     </select>
     <input  type="text" name="yltext" id="yltxt" value="yanleigis1">
     <input  type="text" name="yltext" id="yltxt" value="yanleigis2">
</p>
 <p>
   <input type="button" id="ylok" value="获得属性">
 </p>
</BODY>
</html>

 

posted @ 2009-03-09 17:05  闫磊博客  阅读(587)  评论(0编辑  收藏  举报