有人能用这个简单的隐藏元素脚本告诉我我做错了什么 JQuery的?当我点击按钮时,它意味着隐藏免责声明标签中的文字。感谢。
的index.html:
<!DOCTYPE HTML">
<html>
<head>
<title></title>
<meta name="" content="">
<script src="script.js" type="text/javascript"></script>
<script type='text/javascript' src='jquery.js'></script>
</head>
<body>
<input type="button" id="hideButton" value="hide"/>
<div id="disclaimer">
<p>This is a disclaimer</p>
</div>
</body>
</html>
的script.js:
$('#hideButton').click(function() {
$('#disclaimer').hide();
});
答案 0 :(得分:1)
等到你的dom加载然后加载脚本
演示:http://jsfiddle.net/epinapala/Pm2k6/3/
<!DOCTYPE HTML">
<html>
<head>
<title></title>
<meta name="" content="">
<script src="script.js" type="text/javascript"></script>
<script type='text/javascript' src='jquery.js'></script>
</head>
<body>
<input type="button" id="hideButton" value="hide"/>
<div id="disclaimer">
<p>This is a disclaimer</p>
</div>
<script>
$('#hideButton').click(function() {
$('#disclaimer').hide("slow");
});
</script>
</body>
</html>
或者你可以使用
$(document).ready(function(){
//this will be executed after dom is loaded.
});
答案 1 :(得分:0)
$(document).ready(function(){
$('#hideButton').click(function() {
$('#disclaimer').hide();
});
});
你应该把它放在准备好的文件中
也请在jquery.js
script.js
答案 2 :(得分:-1)
另一种方式
<div id="disclaimer" style="block">
<p>This is a disclaimer</p>
</div>
<script>
$('#hideButton').click(function() {
$('#disclaimer').css('display','none');
});
</script>