为什么javascript中元素的宽度没有增加
我有以下代码: 它既可以增加元素的宽度,也可以减少元素的宽度为什么javascript中元素的宽度没有增加,javascript,Javascript,我有以下代码: 它既可以增加元素的宽度,也可以减少元素的宽度 function _width(ele, size, speed){ ele = document.getElementById(ele); var eleWidth = ele.clientWidth, incInWidth = setInterval(function(){ if (eleWidth<size) { increase();};
function _width(ele, size, speed){
ele = document.getElementById(ele);
var eleWidth = ele.clientWidth,
incInWidth = setInterval(function(){
if (eleWidth<size) { increase();};
if (eleWidth>size) { decrease();};
if (eleWidth=size) { stopInc();};
}, speed),
increase = function(){
ele.style.width = eleWidth + ' px';
eleWidth++;
},
decrease = function(){
ele.style.width = eleWidth + ' px';
eleWidth--;
},
stopInc =function(){
clearInterval(incInWidth);
};
};
我刚刚在第一个代码中添加了比第二个代码更多的功能,如果第二个代码使用setInterval
运行得很好,那么使用这种思想,在使用setInterval
的问题上,我没有错误第一个代码
那么错误在哪里呢 请给我们您的示例电话。您可能在这段代码中出错:
if (eleWidth < size) { increase();};
if (eleWidth > size) { decrease();};
if (eleWidth == size) { stopInc();};
if(eleWidthsize){decrease();};
如果(eleWidth==size){stopInc();};
编辑:
完整解决方案:第一种方法中没有使用“大小”,是吗?很抱歉,输入错误。。如果(eleWidth=size)错了,谢谢你的
if(eleWidth=size)
错了。请用评论询问细节,而不是单独回答。我不能这样做,因为我没有50%的声誉。然后耐心地回答其他问题:)删除你的“解决方案”。您在代码段的第3行复制了作者的错误。提示:=!===因为我引用了他的密码?你只是在批评他,但不给他答案或帮助。。。
if (eleWidth < size) { increase();};
if (eleWidth > size) { decrease();};
if (eleWidth == size) { stopInc();};