javascript - 我可以在 Js 中更改对象的大小吗?

标签 javascript jquery html css

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

<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)

}

最佳答案

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

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

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

setAttribute 函数的 jQuery 版本,attr 方法接受一个对象:

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

关于javascript - 我可以在 Js 中更改对象的大小吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23723648/

相关文章:

javascript - 将 HTML 代码存储在变量中(对于浏览器来说更快?)

javascript - Moment.js 的语言环境和特定日期格式

javascript - 添加到 Jquery EasyUI 树的链接(带有 json 数据)

html - Servlet返回“HTTP状态404请求的资源(/Servlet)不可用”

jquery - 滚动内部子 div

JavaScript:完全旋转一个字符串,然后在给定数字输入的另​​一个方向上旋转该字符串

javascript - 正则表达式从字符串中提取路径/文件名

javascript - PHP 中的 jQuery/JavaScript 输出

jquery - 如何淡入 .html()

html - 如何应用 SVG 使其在 IE 背景图像中工作