<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type ="text/javascript" src ="jquery-1.3.2-vsdoc2.js" ></script>
<script type ="text/javascript" >
$("#buttonshow").bind("click", function(event) { $("#divtest").show(); });
$("#buttonhide").bind("click", function(event) { $("#divtest").hide(); });
$("#buttonchange").bind("click", function(event) { $("#divtest").html("dddddddd"); });
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="divtest">divtest</div>
<input id="buttonshow" type ="button" value="显示" />
<input id="buttonhide" type ="button" value="隐藏" /><br />
<input id="buttonchange" type ="button" value="修改内容" />
</div>
</form>
</body>
</html>
求助为什么jquery的代码不起作用呢?求指教
<head runat="server">
<title></title>
<script type ="text/javascript" src ="jquery-1.3.2-vsdoc2.js" ></script>
<script type ="text/javascript" >
$("#buttonshow").bind("click", function(event) { $("#divtest").show(); });
$("#buttonhide").bind("click", function(event) { $("#divtest").hide(); });
$("#buttonchange").bind("click", function(event) { $("#divtest").html("dddddddd"); });
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="divtest">divtest</div>
<input id="buttonshow" type ="button" value="显示" />
<input id="buttonhide" type ="button" value="隐藏" /><br />
<input id="buttonchange" type ="button" value="修改内容" />
</div>
</form>
</body>
</html>
求助为什么jquery的代码不起作用呢?求指教
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="divtest">divtest</div>
<input id="buttonshow" type ="button" value="显示" />
<input id="buttonhide" type ="button" value="隐藏" /><br />
<input id="buttonchange" type ="button" value="修改内容" />
</div>
</form>
<script type ="text/javascript" >
$("#buttonshow").bind("click", function(event) { $("#divtest").show(); });
$("#buttonhide").bind("click", function(event) { $("#divtest").hide(); });
$("#buttonchange").bind("click", function(event) { $("#divtest").html("dddddddd"); });
</script>
</body>
</html>
或者看看JQ的使用教程,第一步就会告诉你一个READY方法,把这些JS语句放在READY方法里面。原理自己看教程。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type ="text/javascript" src ="js/jquery-1.4.2.min.js" ></script>
<script type ="text/javascript" >
/*
$(function(){//Jquery代码来生效 作用相当于 window.onload 但有区别 自己好好看看教程
$("#buttonshow").bind("click", function(event) { $("#divtest").show(); });
$("#buttonhide").bind("click", function(event) { $("#divtest").hide(); });
$("#buttonchange").bind("click", function(event) { $("#divtest").html("dddddddd"); });
});
*/
//你可以比较两种方法
///////
window.onload = init;
function init(){
$("#buttonshow").bind("click", function(event) { $("#divtest").show(); });
$("#buttonhide").bind("click", function(event) { $("#divtest").hide(); });
$("#buttonchange").bind("click", function(event) { $("#divtest").html("dddddddd"); });
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="divtest">divtest</div>
<input id="buttonshow" type ="button" value="显示" />
<input id="buttonhide" type ="button" value="隐藏" /><br />
<input id="buttonchange" type ="button" value="修改内容" />
</div>
</form>
</body>
</html>
$("#buttonshow").bind("click", function(event) { $("#divtest").show(); });
$("#buttonhide").bind("click", function(event) { $("#divtest").hide(); });
$("#buttonchange").bind("click", function(event) { $("#divtest").html("dddddddd"); });});
+1
LZ的写法,在执行js的时候,控件还不存在呢。