Jquery else if statement
Jquery else if statement
我想出了一些来自外部页面的jquery,并在另一个页面上显示隐藏的div(#section2)。问题是,我似乎无法让#section3和#section2一样工作。这是代码。
jQuery(document).ready(function() {
var hash = window.location.hash.substring(0);
jQuery(hash).css({
"display": "block"
});
if (hash != '#section2') {
jQuery('#section1').css({
"display": "block"
});
}
else {
jQuery('#section1').css({
"display": "none"
});
}
});
如果if(hash != '#section3'){
jQuery('#section1').css({"display":"block"});
}
我似乎只能让#section2或#section3在输入它们各自的带有哈希的URL时显示,并隐藏section1。我似乎无法让它们同时正常工作。基本上我需要一些能生产的东西CCD_ 2。我正在学习,所以任何帮助都将不胜感激。
jQuery(document).ready(function() {
var hash = window.location.hash.substring(0);
jQuery(hash).css({
"display": "block"
});
if (hash != '#section2' && hash != '#section3') {
jQuery('#section1').css({
"display": "block"
});
}
else {
jQuery('#section1').css({
"display": "none"
});
}
});
此外,考虑使用jQuery .show()
和.hide()
,而不是那些css更改(效果相同,但不那么冗长,并且它会记住以前的状态)。
Try;
$(document).ready(function(){
var sectionhash = window.location.hash.substring(0);
$(hash).css({"display":"block"});
if(hash != '#section2' || hash != '#section3'){
$('#section1').css({"display":"block"});
}else {
$('#section1').css({"display":"none"});
}
});
或
$(document).ready(function(){
var sectionhash = window.location.hash.substring(0);
$(hash).css({"display":"block"});
if(hash != '#section2'){
$('#section1').css({"display":"block"});
}else if(hash != '#section3'){
$('#section1').css({"display":"block"});
}else {
$('#section1').css({"display":"none"});
}
});
(function($) {
var hash = window.location.hash;
$(hash).css('display', 'block');
$("#section1").toggle(!(hash=='#section2'||hash=='#section3'));
})(jQuery);
相关文章:
- Jquery else if statement
- Rails 3 if statement with jQuery?
- JQuery Else if statement?
- 在jQuery .load Ajax之后执行if-statement
- Javascript if statement if (ball.style.left === '0px'
- If-Statement中的Javascript元素验证
- Javascript document.cookie if statement
- Javascript Logic In a loop/if statement
- Javascript if statement Google Tools
- Javascript IF statement
- ActionScript 3 If/ Else If Statement
- Javascript if-statement vs. comparsion
- Javascript condense if statement
- 嵌套的 if's:使用 if (x) {statement;} 还是 if (!x) 返回更好;陈述;
- Javascript optimizing if statement
- Javascript and CSS if statement
- JQUERY, AJAX if else statement
- Vuejs IF statement
- Datatables Find Replace If Statement
- javascript msgbox if statement