2013-08-21 61 views
0
$("#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和實際寬度/高度寬度一種功能

+1

爲什麼重要?好奇... – epascarello

+0

我需要它爲我的HTML5畫布... – super

+5

爲什麼你不只是做一個 - > http://jsfiddle.net/7ntfv/但我真的不明白爲什麼你不能只是做'$('#elem').css('width',value).attr('width',value);'? – adeneo

回答

1

怎麼樣一個新的jQuery功能:

$.fn.fixWidths = function(width) { 
    return $(this).width(width).attr('width', width); 
}; 

$(ELEM).fixWidths(寬);

0

爲什麼不寫一個?

function setWidths(id, width){ 
    $('#' + id).width(width); 
    $('#' + id).attr('width', width); 
} 
0

嘗試以下操作:

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";  

我希望它能幫助。