刚用jquery遇到了这个问题,click没有反应。
jquery是这样的
<script type="text/javascript">
$(document).ready(function(){
alert("1");
$("#b01").click(function(){
alert("2");
});
});
</script>这个是按钮<button id="b01" type="button">Change Content</button>页面刷新是会弹出 1 这个框,但是点击按钮 2 的框不但出来,没有反应,这时为什么啊!!
jquery是这样的
<script type="text/javascript">
$(document).ready(function(){
alert("1");
$("#b01").click(function(){
alert("2");
});
});
</script>这个是按钮<button id="b01" type="button">Change Content</button>页面刷新是会弹出 1 这个框,但是点击按钮 2 的框不但出来,没有反应,这时为什么啊!!
这部分你后面生成的,$(document).ready时还没加载这部分。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> </head><body>
<script type="text/javascript">
$(document).ready(function(){
alert("1");
$("#b01").click(function(){
alert("2");
});
});
</script>
这个是按钮<button id="b01" type="button">Change Content</button>
</body>
</html>
如果是没加载的问题,那有什么办法可以解决啊?
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import = "java.util.*" %>
<%@ page import = "com.scnudims.model.*" %>
<!Doctype html public "-//w3c//dtd html 4.01 transitional//en"
"http://www.w3c.org/tr/1999/rec-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<style type="text/css">
<!--
.STYLE1 {
font-size: medium
}
-->
</style>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<!--[if IE 7]><style>#dropdownMenu li ul ul {margin-left: 100px;}</style><![endif]-->
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
alert("1");
$("#b01").click(function(){
alert("2");
});
});
</script>
<div id="container">
<div id="wrapper">
<jsp:include page="head.jsp"></jsp:include>
<div id="header">
<div class="intro"> <form method="get" id="searchform" action="#">
<div>
<input class="searchField" type="text" value="" name="q" />
<input class="searchSubmit" type="submit" value="" />
<input type="hidden" name="sitesearch" value="" />
</div>
</form>
</div>
</div>
<div id="content">
<button id="b01" type="button">Change Content</button>
<form action="stmessageregister.action" method="post" name="stmessageregister" >
<label class="f2">收件人:</label>
<input type="text" name="stmessage.tname" size=20 id="tname" />
<div id="suggest"></div>
<br>
<textarea name="stmessage.message" cols="90" rows="10" class="text" id="message"></textarea><br>
<input type="submit" name="submit" class="button1" value="发送" />
<br/>
</form> <big class="dwnld" style="padding-top: 10px;"><a href="#"></a>
</big> <a class="backToTop" href="#"> </a>
</div>
<div id="sidebar">
<ul id="news">
<li> <a href="#"> <img src="images/temp/news1.jpg" alt="" width="54" /> </a>
<h3>News Heading H3</h3>
<p>我们爱美女 <br />
<a href="#">More »</a></p>
</li>
<li> <a href="#"> <img src="images/temp/news2.jpg" alt="" width="54" /> </a>
<h3>News Heading H3</h3>
<p>我们爱美女 <br />
<a href="#">More »</a></p>
</li>
<li> <a href="#"> <img src="images/temp/news3.jpg" alt="" width="54" /> </a>
<h3>News Heading H3</h3>
<p>我们爱美女 <br />
<a href="#">More »</a></p>
</li>
</div>
<jsp:include page="foot.jsp"></jsp:include>
</div>
</div>
</body>
</html>
这个是我的页面,可以帮我看看问题出在哪吗?
<input type="button" id="b01" value="Change Content"/>
试试button这个标签好像现在不大能正常用了。。
没有问题,FF,ie和谷歌都试过。你确定你按的是Change Content而不是《发送》?
那就可能是你include的部分也有个元素id叫b01,没记错的话ID选择器的话只会返回第一个元素。