javascript 函数修改全局变量无效
varstatu=3;varwhosnext=function(){if(statu=3){aboutout();}elseif(statu=2){orbout();}e...
var statu = 3;
var whosnext = function () {
if ( statu = 3) {
aboutout();
} else if ( statu = 2) {
orbout();
} else if ( statu = 4) {
contactout();
}else {
caseout();
}
}
var aboutclick = function () {
whosnext();
statu = 3;
aboutin();
}
var contactclick = function () {
whosnext();
statu = 4;
contactin();
}
var orbclick = function () {
whosnext();
statu = 2;
orbin();
}
var caseclick = function () {
whosnext();
statu = 1;
casein();
}
html:
<ul class="list-inline nav_list">
<li onclick="caseclick()"><a href="#" onclick="caseclick()">案例</a></li>
<li onclick="orbclick()"><a href="#" onclick="orbclick()">服务</a></li>
<li onclick="aboutclick()"><a href="#" onclick="aboutclick()">关于</a></li>
<li onclick="contactclick()"><a href="#" onclick="contactclick()">联系</a></li>
</ul>
我想每次点击修改statu的值,但是好像statu没有变化一直是3 展开
var whosnext = function () {
if ( statu = 3) {
aboutout();
} else if ( statu = 2) {
orbout();
} else if ( statu = 4) {
contactout();
}else {
caseout();
}
}
var aboutclick = function () {
whosnext();
statu = 3;
aboutin();
}
var contactclick = function () {
whosnext();
statu = 4;
contactin();
}
var orbclick = function () {
whosnext();
statu = 2;
orbin();
}
var caseclick = function () {
whosnext();
statu = 1;
casein();
}
html:
<ul class="list-inline nav_list">
<li onclick="caseclick()"><a href="#" onclick="caseclick()">案例</a></li>
<li onclick="orbclick()"><a href="#" onclick="orbclick()">服务</a></li>
<li onclick="aboutclick()"><a href="#" onclick="aboutclick()">关于</a></li>
<li onclick="contactclick()"><a href="#" onclick="contactclick()">联系</a></li>
</ul>
我想每次点击修改statu的值,但是好像statu没有变化一直是3 展开
展开全部
if ( statu = 3) 所有if判断后面的条件都写错了,判断是用双等于‘==‘ 或值和类型都比较的用三等号’===‘;单等号是赋值。还有事件没有必要绑2次,可以把li上的去掉,修改或的代码:
<body>
<ul class="list-inline nav_list">
<li><a href="###" onclick="caseclick()">案例</a></li>
<li><a href="###" onclick="orbclick()">服务</a></li>
<li><a href="###" onclick="aboutclick()">关于</a></li>
<li><a href="###" onclick="contactclick()">联系</a></li>
</ul>
<script type="text/javascript">
var statu = 3;
var whosnext = function () {
if (statu == 3) {
//aboutout();
console.log(statu);
} else if (statu == 2) {
//orbout();
console.log(statu);
} else if (statu == 4) {
//contactout();
console.log(statu);
}else {
//caseout();
console.log(statu);
}
}
var aboutclick = function () {
whosnext();
statu = 3;
//aboutin();
}
var contactclick = function () {
whosnext();
statu = 4;
//contactin();
}
var orbclick = function () {
whosnext();
statu = 2;
//orbin();
}
var caseclick = function () {
whosnext();
statu = 1;
//casein();
}
</script>
</body>
<body>
<ul class="list-inline nav_list">
<li><a href="###" onclick="caseclick()">案例</a></li>
<li><a href="###" onclick="orbclick()">服务</a></li>
<li><a href="###" onclick="aboutclick()">关于</a></li>
<li><a href="###" onclick="contactclick()">联系</a></li>
</ul>
<script type="text/javascript">
var statu = 3;
var whosnext = function () {
if (statu == 3) {
//aboutout();
console.log(statu);
} else if (statu == 2) {
//orbout();
console.log(statu);
} else if (statu == 4) {
//contactout();
console.log(statu);
}else {
//caseout();
console.log(statu);
}
}
var aboutclick = function () {
whosnext();
statu = 3;
//aboutin();
}
var contactclick = function () {
whosnext();
statu = 4;
//contactin();
}
var orbclick = function () {
whosnext();
statu = 2;
//orbin();
}
var caseclick = function () {
whosnext();
statu = 1;
//casein();
}
</script>
</body>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询