日期:2014-05-16  浏览次数:20341 次

新手 jQuery 问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title></title>
  <script src="../JS/jquery-1.4.4.min.js" type="text/javascript">
  $("#Button1").bind("click", function (event) { $("#ss").show(); });
  $("#Button2").bind("click", function (event) { $("#ss").hide(); });
  </script>
</head>
<body>
<div id="ss">Hello World</div>
<input id="Button2" type="button" value="隐藏" />
<input id="Button1" type="button" value="显示" />

</body>
</html>


为什么没作用

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title></title>
<script src="../JS/jquery-1.4.4.min.js" type="text/javascript">
$(function(){
$("#Button1").bind("click", function (event) { $("#ss").show(); });
$("#Button2").bind("click", function (event) { $("#ss").hide(); });
})
</script>
</head>
<body>
<div id="ss">Hello World</div>
<input id="Button2" type="button" value="隐藏" />
<input id="Button1" type="button" value="显示" />

</body>
</html>


注意 顺序, dom还没加载
------解决方案--------------------
大哥引用的js文件是js文件。。自己写诗自己写的。。不要混为一谈。。。
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title></title>
  <script src="../JS/jquery-1.4.4.min.js" type="text/javascript"></script>
<script>
  $("#Button1").bind("click", function (event) { $("#ss").show(); });
  $("#Button2").bind("click", function (event) { $("#ss").hide(); });
  </script>
</head>
<body>
<div id="ss">Hello World</div>
<input id="Button2" type="button" value="隐藏" />
<input id="Button1" type="button" value="显示" />

</body>
</html>