jquery 用ID取某个元素下的某个ID元素
程序员文章站
2022-07-05 13:45:11
...
- <html>
- <head><script type="text/javascript" src="jquery-1.7.2.min.js"></script></head>
- <body>
- <div id="div_1">
- <input type="text" id="txt1" name="txtt" value="111"/>
- <label id="sumv">5.00</label>
- </div>
- <div id="div_3">
- <input type="text" id="txt2" name="txtt" value="222"/>
- <label id="sumv" name="sumv_3">10.00</label>
- </div>
- <input type="button" value="BUTTON" onclick="test1();"/>
- <input type="button" value="BUTTON2" onclick="test2();"/>
- </body>
- <script language="javascript">
- function test1() {
- alert($("#div_1 #sumv").text());
- }
- function test2() {
- alert($("#div_3 label[id='sumv']").text());//firefox和IE下都有值
- alert($("#div_3 #sumv").text());//firefox下有值
- }
- </script>
- </html>
<html> <head><script type="text/javascript" src="jquery-1.7.2.min.js"></script></head> <body> <div id="div_1"> <input type="text" id="txt1" name="txtt" value="111"/> <label id="sumv">5.00</label> </div> <div id="div_3"> <input type="text" id="txt2" name="txtt" value="222"/> <label id="sumv" name="sumv_3">10.00</label> </div> <input type="button" value="BUTTON" onclick="test1();"/> <input type="button" value="BUTTON2" onclick="test2();"/> </body> <script language="javascript"> function test1() { alert($("#div_1 #sumv").text()); } function test2() { alert($("#div_3 label[id='sumv']").text());//firefox和IE下都有值 alert($("#div_3 #sumv").text());//firefox下有值 } </script> </html>
点击BUTTON2时,用firefox就可以出#sumv的值10,但在IE下,就不能,必须用
上一篇: jquery的用法