如何使用jQuery獲取邊框樣式?以下是不工作使用jQuery獲取邊框樣式
$('#get').click(function() {
var x = $('div').css('borderStyle');
alert(x)
})
檢查http://jsfiddle.net/s7YAN/31/
如何使用jQuery獲取邊框樣式?以下是不工作使用jQuery獲取邊框樣式
$('#get').click(function() {
var x = $('div').css('borderStyle');
alert(x)
})
檢查http://jsfiddle.net/s7YAN/31/
alert($("div.myel").css("border-top-style"));
http://jsfiddle.net/jbrooksuk/YJQAS/
看來,你是無法得到整個邊框樣式一氣呵成。您需要明確指出您想要的部分。
顯然你必須指定一面。
就像是:
var x = $('div').css("border-left-style");
我想這是因爲每一面可以具有不同的尺寸,顏色和樣式。
速記CSS屬性(如保證金, 背景,邊框)不被支持。例如,如果要檢索 提供的邊距,請使用: $(elem).css('marginTop')和 $(elem).css('marginRight')等等。
基本上border-style
只是簡單的設置四邊的邊框樣式。它也可以像border-style: dotted solid double dashed;
一樣使用,但通常您只需編寫border-style: dashed;
,這就是爲什麼它感覺像一個簡單的屬性。 margin
同樣發生,說margin: 20px;
其實意味着margin: 20px 20px 20px 20px;
(它也是一個速記屬性)。
這就是爲什麼您需要使用border-top-style
,border-right-style
等來獲得邊框樣式。
檢查了這一點。看來你必須設置明確的一面: How to get border width in jQuery/javascript 不完全一樣,但同樣的原則應適用於你,這表現在這裏:
alert($('div').css('border-top-style'));