像Unity3D这样的Jquery更新函数
我的变量nim没有更新seconds调用像Unity3D这样的Jquery更新函数,jquery,function,Jquery,Function,我的变量nim没有更新seconds调用 $( "#upbutton" ).click(function() { var nim = $("a").css("margin-top").replace("px", ""); nim+=70; $("#moved").css('margin-top',nim+'px'); }); nim=70且不会更改。您将从文档中的第一个标记获取nim的值,然后使用移动的id在元素上更新它 如果要移动该元素,是否应该从正在设置它的同一元素
$( "#upbutton" ).click(function() {
var nim = $("a").css("margin-top").replace("px", "");
nim+=70;
$("#moved").css('margin-top',nim+'px');
});
nim=70且不会更改。您将从文档中的第一个标记获取nim的值,然后使用移动的id在元素上更新它 如果要移动该元素,是否应该从正在设置它的同一元素获取它?
$(“a”).css(“margin top”)
返回DOM中第一个元素的margin top
,您不更新该属性,您期望得到什么?将属性的值存储在click处理程序之外,并改用它。
var nim = $("a").css("margin-top").replace("px", "");
$( "#upbutton" ).click(function() {
nim += 70;
$("#moved").css( 'margin-top', nim + 'px' );
});