<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta charset="UTF-8">
<script type="text/javascript" src="jquery.js"></script>
 </head>


 <body>
 <div id="div">
    <div><input type="text" value="as" id="11">qiue</div>
<div><input type="text" value="ww" id="12" />qfweq</div>
<div id="33"><input type="text" value="qq" id="13" >qfe</input></div>
<p id="a">dawcs</p>
</div>
 <script >
$(function(){
var a1 = $("#11").val();
var a2 = $("#12").val();
var a3 = $("#13").val();
alert("取各input的val:a1:"+a1+" ,a2:"+a2+" ,a3:"+a3);
//alert("取各input的text:first:"+$("#11").text()+" ,second:"+$("#12").text()+" ,third:"+$("#13").text());

//alert("取各input的html:first:"+$("#11").html()+" ,second:"+$("#12").html()+" ,third:"+$("#13").html());

alert(document.getElementById("13").value);
//这个不行:alert($("#12").value);

//alert("取各input的innerText:first:"+document.getElementById("11").innerText+" ,second:"+document.getElementById("12").innerText+" ,third:"+document.getElementById$("13").innerText);

//alert("取各input的innerHTML:first:"+document.getElementById("11").innerHTML+" ,second:"+document.getElementById("12").innerHTML+" ,third:"+document.getElementById$("13").innerHTML);
//获取input标签后面的文本:
alert($("#11").parent().text());
alert($('#11').parent().html());
alert("获取到的第三个input后面的文本:"+document.getElementById("13").nextSibling.data);
//undefined
alert($('#13').parent().innerText);



});
 </script>
 
 </body>

</html>

总结:用document.getElementById("13").nextSibling.data(首推)或parent().text()或parent().html()



本文转载:CSDN博客