我努力獲得一些var'ed值到jquery選擇器。在jquery var'ed veiwport寬度/高度插入
// this works below
$(".portrait").css({
"width": viewportwidth + 'px',
"height": viewportheight + 'px'
});
,但我不得不搬到從上面的jQuery的CSS選擇離開,而是使用.attr,因爲我需要的!重要的選擇要應用到我的寬度和高度。
我做到這一點的唯一方法,就是使用.attr(我認爲)
// this works below but I can only put a hardcoded value in
$('.portrait').attr('style', 'width: 0px !important;');
// this is my attempt but fails
$('.portrait').attr('style', 'width: viewportwidth + 'px' !important;');
// below is exactly what I ideally need to work, multiple styles with !important
$('.portrait').attr({
'style', 'width: viewportwidth + 'px' !important;'
'style', 'height: viewportheight + 'px' !important;'
});
// but it does not work cause of my bad coding.
如果任何人都可以對周圍的工作建議或修正,這將是這樣的幫助。如果你需要我更詳細地解釋讓我知道。
在此先感謝:-)
喬希
你如何做到這一點? - 謝謝,不知道:/ – Joshc
我建議你看看這些 - > http://stackoverflow.com/faq – ManseUK