87,902
社区成员
发帖
与我相关
我的任务
分享
0 看看$("#txtemail").length是0还是1
[quote=引用 6 楼 rui888 的回复:]<!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p").click(function(){ alert($("#txtemail").html()); }); }); </script> </head> <body> <span id="txtemail">+34-571-85285227</span> <p>如果您点击我,我会消失。</p> <p>点击我,我会消失。</p> <p>也要点击我哦。</p> </body> </html>
$("#txtemail").html()在span前还是span后?
看看$("#txtemail").length是0还是1
alert($("#txtemail").text());
本地测试可以显示html内容 你可以下输出$("#txtemail")看一下是什么
保证你获取的时候 span 已经加载到页面上
<!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p").click(function(){ alert($("#txtemail").html()); }); }); </script> </head> <body> <span id="txtemail">+34-571-85285227</span> <p>如果您点击我,我会消失。</p> <p>点击我,我会消失。</p> <p>也要点击我哦。</p> </body> </html>
是.text() .html()是把span里面的内容给清空重新写 比如$(#txtemail).html(newContent);//把之前里面的内容替换成新内容