2014-05-18 66 views
0

所以我有一个对象,当我在导航中单击时加载数据。加载特定数据时是否可以更改该对象的大小?我可以在Js中更改对象的大小吗?

<object id="box" width="250" height="250" data=""></object> 

和js,它加载数据但不更改大小。

document.getElementById("banner").onclick = function(){ 
    document.getElementById("box") 
      .setAttribute("data", "sfw/danser.swf", 'height', 600, 'width', 150) 

} 

回答

4

你应该设置每个单独的属性,该setAttribute函数不接受超过2个参数:

.setAttribute("data", "sfw/danser.swf") 
.setAttribute('height', 600) 
.setAttribute('width', 150) 

https://developer.mozilla.org/en-US/docs/Web/API/Element.setAttribute

的jQuery的版本setAttribute功能,该attr方法,接受对象:

$("#banner").on('click', function(event) { 
    $("#box").attr({ 
     "data" : "sfw/danser.swf", 
     "height" : 600, 
     "width" : 150 
    }); 
}); 
+0

因为它被标记为[tag:jQuery],所以值得一提的是jQuery方式允许'$(“#box”)。attr({“data”:“swf/danser.swf”,“height”:“600px” ,“width”; 150px“})' –

+0

@BenjaminGruenbaum是的,谢谢你提到它。 – undefined

相关问题