Javascript 这个脚本需要改进吗
我在StackOverflow上找到的这个脚本Javascript 这个脚本需要改进吗,javascript,jquery,Javascript,Jquery,我在StackOverflow上找到的这个脚本 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <style> #appear_div { display: none; } </style> <script type="text
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
#appear_div { display: none; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#appear').click(function() { $('#appear_div').show(); });
});
</script>
</head>
<body>
<input type="checkbox" id="appear">
<div id="appear_div">
<input type="checkbox" id="cb1">Check me <input type="text" id="text1">
</div>
</body>
</html>
#显示{display:none;}
$(文档).ready(函数(){
$('#出现'')。单击(函数(){$('#出现''u div')。显示();});
});
检查我
我需要这方面的进一步发展
当取消选中复选框时,我想隐藏div
&如何为其添加褪色效果
Thanx假设您正在谈论标有id=cb1的复选框
$(document).ready(function() {
$("#cb1").click(function() {
if (this.checked) {
$('#appear_div').fadeIn('slow');
}
else {
$('#appear_div').fadeOut('slow');
}
});
});
如果您正在谈论另一个标有id=的复选框,请使用此复选框
$(document).ready(function() {
$("#appear").click(function() {
if (this.checked) {
$('#appear_div').fadeIn('slow');
}
else {
$('#appear_div').fadeOut('slow');
}
});
});
假设您正在谈论标有id=cb1的复选框
$(document).ready(function() {
$("#cb1").click(function() {
if (this.checked) {
$('#appear_div').fadeIn('slow');
}
else {
$('#appear_div').fadeOut('slow');
}
});
});
如果您正在谈论另一个标有id=的复选框,请使用此复选框
$(document).ready(function() {
$("#appear").click(function() {
if (this.checked) {
$('#appear_div').fadeIn('slow');
}
else {
$('#appear_div').fadeOut('slow');
}
});
});
您可以按如下方式进行淡入切换:
$(function() {
$('#appear').change(function() {
$('#appear_div').animate({opacity: this.checked ? 1 : 0});
}).change();
});
。如果是,我们将不透明度设置为1(在中褪色),否则将其更改为0(在中褪色),最后一个调用是在页面首次加载时正确设置状态。如果要更改速度,例如2秒,只需将其添加为下一个选项:
$('#appear_div').animate({opacity: this.checked ? 1 : 0}, 2000);
您可以按如下方式进行淡入切换:
$(function() {
$('#appear').change(function() {
$('#appear_div').animate({opacity: this.checked ? 1 : 0});
}).change();
});
。如果是,我们将不透明度设置为1(在中褪色),否则将其更改为0(在中褪色),最后一个调用是在页面首次加载时正确设置状态。如果要更改速度,例如2秒,只需将其添加为下一个选项:
$('#appear_div').animate({opacity: this.checked ? 1 : 0}, 2000);
好问题。。还是不想学jQuery?好吧,我不是网络开发者。。我对我的第一个网站的开发和工作非常着迷。所以我有时会很傻…好问题。。还是不想学jQuery?好吧,我不是网络开发者。。我对我的第一个网站的开发和工作非常着迷。所以我有时会很傻…
$(this)。checked
应该是这个。checked
,它不是jQuery属性,而是直接DOM属性。$(this)。checked
应该是这个。checked
,它不是jQuery属性,而是直接DOM属性。