[英]Reload page after switching toggle switch back on
I want the page to reload after the toggle is switched back to data-on JSP: 我希望在切换切换回基于JSP的数据后重新加载页面:
<input type="checkbox" class="expander" id="toggle"
data-on="Portfolio" data-off="Topology" checked
data-toggle="toggle" data-onstyle="success">
</div>
Jquery: jQuery:
$(document).ready(function() {
var count = 0;
$('#toggle').change(function() {
if (this.checked)
$('#project-list-area').fadeIn('slow'),
$('#topology').fadeOut('slow');
count++;
if (count === 2)
window.location.reload;
else
$('#topology').fadeIn('slow'),
$('#project-list-area').fadeOut('slow');
});
});
You need to use brackets for your if
and else if
is more than 1 line. if
和else if
超过1行, else if
需要使用方括号。
Also window.location.reload()
is a method so you need parentheses. 另外,
window.location.reload()
是一种方法,因此需要括号。
$(document).ready(function() {
var count = 0;
$('#toggle').change(function() {
if (this.checked){
$('#project-list-area').fadeIn('slow'),
$('#topology').fadeOut('slow');
count++;
}
if (count === 2)
window.location.reload();
else{
$('#topology').fadeIn('slow'),
$('#project-list-area').fadeOut('slow');
}
});
});
cleaned up a bit, check out toggleFade()
: 清理了一下,签出
toggleFade()
:
$(document).ready(function() {
var count = 0;
$('#toggle').change(function() {
if (this.checked) count++;
if (count === 2) window.location.reload();
$('#topology').fadeToggle('slow'),
$('#project-list-area').fadeToggle('slow');
});
});
User if ($(this).prop("checked")) instead of if (this.checked) and window.location.reload(); 用户if($(this).prop(“ checked”))而不是if(this.checked)和window.location.reload(); is a method
是一种方法
$(document).ready(function () {
var count = 0;
$('#toggle').change(function () {
if ($(this).prop("checked")) {
$('#project-list-area').fadeIn('slow'),
$('#topology').fadeOut('slow');
}
count++;
if (count === 2)
window.location.reload();
else {
$('#topology').fadeIn('slow'),
$('#project-list-area').fadeOut('slow');
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.