码迷,mamicode.com
首页 > 其他好文 > 详细

当传递的参数和全局的变量名相同的时候

时间:2014-11-26 20:26:59      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:io   ar   sp   on   log   cti   bs   html   ad   


var $a = $("a");
var topValue = $("#four-choices").offset().top * 1.5 + ($("two-wide-cols").height());

var prevTarget = "#tabletop";


$(document).ready(function($) {
$("#fabric,#throws,#lighting").hide();
$a.click(function(event) {
event.preventDefault();
target = $(this).attr("href");
scrollToTarget(target, prevTarget);
});
});

function scrollToTarget(target, prevTarget) {

if (target == prevTarget) return false;
$(prevTarget).fadeOut("slow");
$(target).fadeIn("slow");

$("html,body").animate({
scrollTop: topValue
}, 1000, function() {
window.location.hash = target;
prevTarget = target;
console.log("window.prevTarget:" + window.prevTarget + ",prevTarget: " + prevTarget)
});
}

 

这个地方: 因为参数的名字和全局的名字相同,所以更新的值只是局部prevTarget的值,但是全局变量的值并未发生更新

当传递的参数和全局的变量名相同的时候

标签:io   ar   sp   on   log   cti   bs   html   ad   

原文地址:http://www.cnblogs.com/alicePanZ/p/4123878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!