$("#elem").width(value) //This sets the "CSS" width of elem
$("#elem").attr("width", value) // This sets the "REAL" width of elem
現在,我的問題是,是不存在的,在同一時間同時設置「REAL」和「CSS」寬任何功能?JQuery的 - 設置CSS和實際寬度/高度寬度一種功能
$("#elem").width(value) //This sets the "CSS" width of elem
$("#elem").attr("width", value) // This sets the "REAL" width of elem
現在,我的問題是,是不存在的,在同一時間同時設置「REAL」和「CSS」寬任何功能?JQuery的 - 設置CSS和實際寬度/高度寬度一種功能
怎麼樣一個新的jQuery功能:
$.fn.fixWidths = function(width) {
return $(this).width(width).attr('width', width);
};
$(ELEM).fixWidths(寬);
爲什麼不寫一個?
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";
我希望它能幫助。
爲什麼重要?好奇... – epascarello
我需要它爲我的HTML5畫布... – super
爲什麼你不只是做一個 - > http://jsfiddle.net/7ntfv/但我真的不明白爲什麼你不能只是做'$('#elem').css('width',value).attr('width',value);'? – adeneo