本文介绍了如何用javascript设置对象的边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从JavaScript设置对象的边距。我可以在Opera&
这里是我有的JavaScript:
function SetTopMargin(ObjectID,Value)
{
document.getElementById(ObjectID).style.marginTop = Value.toString()+px;
}
这样调用:
SetTopMargin(test_div_id,100);因此,有没有人知道一些代码可以在Internet Explorer中工作?
谢谢。
解决方案 [更新于2016年]在所有目前的浏览器
document.getElementById(ObjectId).style.marginTop = Value.ToString()+'px';
可以正常工作。
>非常旧的 IE(
.getElementById(ObjectId).style.setAttribute(
'marginTop',Value.ToString()+'px');
I am trying to set the margin of an object from JavaScript. I am able to do it in Opera & Firefox, but the code doesn't work in Internet Explorer.
Here is the JavaScript I have:
function SetTopMargin (ObjectID, Value)
{
document.getElementById(ObjectID).style.marginTop = Value.toString() + "px";
}
And it is called like this:
SetTopMargin("test_div_id", 100);
So does anyone know some code that will work in Internet Explorer?
Thanks.
解决方案 [Updated in 2016] On all current browsers (including IE8+), your code
document.getElementById(ObjectId).style.marginTop = Value.ToString() + 'px';
works fine.
On very old IE (< 8) versions, you must use this non-standard contraption instead:
document.getElementById(ObjectId).style.setAttribute(
'marginTop', Value.ToString() + 'px');
这篇关于如何用javascript设置对象的边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!