Javascript设置左样式不起作用 [英] Javascript set left style doesn't work

查看:96
本文介绍了Javascript设置左样式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

xpos=xpos+1;
document.getElementById("img").style.left=xpos;

我无法在javascript中将xpos值分配给left属性。

I can't assign xpos value to left property in javascript.

推荐答案

尝试添加单位。否则它可能不会被浏览器读取,因为它是无效的CSS

Try adding a unit to it. Otherwise it's probably not being read by the browser due to it being invalid CSS

document.getElementById("img").style.left= xpos + "px";

您通常可以通过查看浏览器开发人员工具的样式窗格来弄清楚这些事情

You can usually figure out these kind of things by looking at the styles pane of your browser's developer tools

这篇关于Javascript设置左样式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆