如果变量 = 数字,则执行 X,否则不执行任何操作
我编写了一个 jquery 代码,它将在悬停时展开某些元素。我希望代码仅在不扩展的情况下扩展。这是我的代码。它似乎无法正常工作。
$(document).ready(function() {
var labelstatus = 0;
});
$(document).ready(function() {
$("a.rm").hover(function () {
if (labelstatus != 1){
$("#expensereduction,#envimpact,#mtextlft,#initaud,#energaud").fadeOut();
var currentFontSize = $('.initiate').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum*3;
$('.initiate').delay(500).animate({
fontSize: newFontSize
});
return false;
var labelstatus = 1;
}
else {
}
});
});
I wrote a jquery code that is going to expand certain elements on hover. I want the code to only expand if not expanded. Here is my code. It doesn't seem to be working correctly.
$(document).ready(function() {
var labelstatus = 0;
});
$(document).ready(function() {
$("a.rm").hover(function () {
if (labelstatus != 1){
$("#expensereduction,#envimpact,#mtextlft,#initaud,#energaud").fadeOut();
var currentFontSize = $('.initiate').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum*3;
$('.initiate').delay(500).animate({
fontSize: newFontSize
});
return false;
var labelstatus = 1;
}
else {
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这...
应该是...
...而这...
应该是...
return
语句之后的代码将不会运行使用
var
使labelstatus
成为函数本地你真的不需要两个
$(document).ready(function() {
调用。将您的代码放入其中,您可以将labelstatus
设为该处理程序的本地代码,以便内部的所有代码都可以使用它.this...
should be...
...and this...
should be...
Code that comes after the
return
statement will not runUsing
var
makeslabelstatus
local to the functionYou really don't need two
$(document).ready(function() {
calls. Put your code in one, and you can makelabelstatus
local to that handler so that all code inside can use it.您在函数内部声明局部变量,因此它们彼此独立。此外,每次都会获得一个新变量,因此以前的值不会保留。
另外,您在分配变量之前调用
return
,这将退出函数,因此分配永远不会发生。您需要在函数外部的范围内声明变量:
另外:parseFloat 函数没有基数参数。
You are declaring local variables inside the functions, so they are independent of each other. Also, you get a new variable each time, so the previous value doesn't persist.
Also, you are calling
return
before assigning the variable, which will exit out of the function, so the assignment will never happen.You need to declare the variable in a scope outside the functions:
Also: the
parseFloat
function doesn't have a radix parameter.labelstatus
不会设置为1
,因为该函数已在之前的行中返回。labelstatus
won't be set to1
as the function is already returned in the line before.