JQuery - 同时设置css和实际宽度/高度宽度一个函数
JQuery - Set both css and real width/height width one function
$("#elem").width(value) //This sets the "CSS" width of elem
$("#elem").attr("width", value) // This sets the "REAL" width of elem
现在,我的问题是,没有任何功能可以同时设置"REAL"和"CSS"宽度吗?
一个新的jQuery函数怎么样:
$.fn.fixWidths = function(width) {
return $(this).width(width).attr('width', width);
};
$(elem(.fixWidths(width(;
为什么不写一个呢?
function setWidths(id, width){
$('#' + id).width(width);
$('#' + id).attr('width', width);
}
尝试以下操作:
var canvas = document.createElement("canvas");
// this sets canvas tag attributes
canvas.width = width;
canvas.height = height ;
// this sets style of canvas
canvas.style.width = width + "px";
canvas.style.height = height + "px";
我希望它有所帮助。
相关文章:
- 如何计算每个元素's的高度,并将这些值用作函数中的变量
- Image.onload 函数为高度和宽度返回零
- Javascript 函数调整窗口高度和宽度
- 为什么函数不会匹配不同数组的宽度和高度
- 展开预览(计算高度:函数)
- 如何在调用 setSource() 函数后重绘或更新 extjs 网格的宽度/高度
- jQuery load() 函数更改输入文本的高度
- Jquery 滚动函数排除可变高度
- 高度在自调用函数中不起作用
- 使用 jquery $(window).width() 有什么好处吗?和高度函数在窗口上.resizeTo( w,h )
- 当花式盒子包装高度发生变化时,如何调用花式框调整大小函数
- JavaScript 边框高度函数 - 匹配两个元素
- 如何访问processing.js'宽度'和'高度'外部processing.js函数
- 在页面高度的范围内调用jQuery函数
- JQuery - 同时设置css和实际宽度/高度宽度一个函数
- jQuery抓取高度和运行函数仅用于此项
- animate函数使用屏幕的高度
- 从iFrame内部调用父函数以更改元素高度
- 文档's总高度函数's的返回值在浏览器刷新时发生更改(F5)
- resize函数未检测到更改浏览器高度