2014-01-20 32 views
1

仍然在學習jQuery,並將感謝任何幫助。jQuery開關按鈕開/關應設置不同的數據狀態和Onclick功能

我目前使用這個jQuery Switchbutton https://github.com/olance/jQuery-switchButton 它使用複選框作爲輸入類型,並創建帶標籤的span標籤。 我怎麼說我想on_label有數據狀態 =「接受」,並off_label 數據狀態 =「拒絕」?

HTML: <input type="checkbox" id="accept-offer"/>

JS: $("input#accept-offer").switchButton({ on_label: "Accept", off_label: "Ignore"
});

謝謝!

+0

你也許可以爲此創建的jsfiddle,它會幫助我們來幫助你更快 – dcodesmith

回答

0

你可以試着這樣做:

$('.switch-button-label.on').data('status','accept'); 
$('.switch-button-label.off').data('status','decline'); 

或:

$('.switch-button-label.on').attr('data-status','accept'); 
$('.switch-button-label.off').attr('data-status','decline'); 
+0

謝謝,麻煩你可能告訴我如何將它包含在js中? – robinyapockets

+0

@robinyapockets只是將這些代碼放入任何加載在'switchButton'文件後面的js文件中。通常,我將它放在一個名爲'script.js'的文件中,並在''標籤前面的頁尾包含此文件。確保你把這個代碼放在'$(function(){});'確保DOM準備好了:) – Felix