2014-03-28 37 views
1

我使用jQuery Button,並具備以下條件:如何將jQuery樣式應用於按鈕?

HTML:

<input class="test" type="checkbox" id="check"><label for="check">Toggle</label> 
<input class="test2" type="checkbox" id="check2"><label for="check2">Hello</label> 

腳本:

$(function() { 
    $("#check").button(); 
}); 
$(function() { 
    $("#check2").button(); 
}); 

CSS:

.ui-button .test { 
    font: 12px Verdana, Helvetica, sans-serif; 
    border-radius: 10px; 
    border: 0; 
    padding-top: 55px; 
    background-image: url(graphics/move.png); 
    background-repeat:no-repeat; 
    background-position:center center; 
    background-size: 48px 48px; 
    box-shadow: 0 4px 4px 0 #888; 
    background-position:center 10px; 

} 

我用.ui-button .test一個按鈕,但CSS不起作用。

+1

使用逗號作爲'.ui-button,.test' – Amit

+0

你在哪裏'.ui-button'元素?否則'.test'不會做任何事情。 –

+0

請先在此處填寫您的完整代碼。 .ui-button元素在哪裏? – dirtyhandsphp

回答

2

由於在這個小提琴中,按鈕元素不是圍繞當前元素創建的。當前元素是隱藏的,一個新創建:

http://jsfiddle.net/ahallicks/KGq56/1/

以不同樣式的按鈕,你將需要改變的CSS,或已被創建後,如http://jsfiddle.net/ahallicks/KGq56/8/應用自定義類的按鈕:

 
$(function() { 
    $("#check").button().next().addClass("test"); 
}); 

However, it is easier to change the HTML to the following with the class applied to the label, not the input http://jsfiddle.net/ahallicks/KGq56/9/ :

<input type="checkbox" id="check"><label for="check" class="test">Toggle</label> 

then you would only need to do the following:

 
$(function() { 
    $("#check").button(); 
}); 

Then you can use the class selector .ui-button.test以適當地設計它。

+0

運作良好。非常感謝你 – user3422998

+1

是的,當jQuery UI向它應用類「ui-helper-hidden-accessible」時,'input'元素被隱藏。但是,創建一個新元素並不完全如此。使用''的'

+1

@ user3422998:您可以直接將類指派給您的標籤,因爲這是jQuery UI使用的元素:'''而不是使用'addClass()'。請參閱[** DEMO **](http://jsfiddle.net/5vdfL/)。如果您可以根據需要設置默認標記,則不需要額外的複雜性和腳本執行。 – Nope

相關問題