
jQuery代码问题if else
<script>$(document).ready(function(){$(#button1).click(function(){if($("#p1").text()=...
<script>
$(document).ready(function(){
$(#button1).click(function(){
if($("#p1").text()=="hello")
alert("p1.text is --hello");
else
alert("p1.text is not --hello");
});
});
</script>
如代码:获取id为button1的按钮。点击出发函数,用if else判断id为p1的文本是否是hello,是则提示是,否则提示不是。这样写哪里有问题?为什么没反映? 展开
$(document).ready(function(){
$(#button1).click(function(){
if($("#p1").text()=="hello")
alert("p1.text is --hello");
else
alert("p1.text is not --hello");
});
});
</script>
如代码:获取id为button1的按钮。点击出发函数,用if else判断id为p1的文本是否是hello,是则提示是,否则提示不是。这样写哪里有问题?为什么没反映? 展开
1个回答
展开全部
$(#button1) 改为 $("#button1"),你需要在选择其中用引号。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |