我正在爲使用jQuery移動和Phonegap的移動開發應用程序。所以我的情況是我需要改變翻轉切換按鈕背景顏色以編程方式。 例如:如果按鈕在背景上,則顏色變爲綠色,否則變爲紅色。我該如何設置?以編程方式更改翻轉開關背景顏色
-2
A
回答
2
這裏是CSS您的需求,
<style>
.ui-btn-active {
background-image: -webkit-gradient(linear,left top,left bottom,from(#44C723),to(#317220));
background-image: -webkit-linear-gradient(#44C723,#317220);
background-image: -moz-linear-gradient(#44C723,#317220);
background-image: -ms-linear-gradient(#44C723,#317220);
background-image: -o-linear-gradient(#44C723,#317220);
background-image: linear-gradient(#44C723,#317220)
}
.ui-btn-down-e{
background-image: -webkit-gradient(linear,left top,left bottom,from(#d2232b),to(#d2232b));
background-image: -webkit-linear-gradient(#d2232b,#d2232b);
background-image: -moz-linear-gradient(#d2232b,#d2232b);
background-image: -ms-linear-gradient(#d2232b,#d2232b);
background-image: -o-linear-gradient(#d2232b,#d2232b);
background-image: linear-gradient(#d2232b,#d2232b)
}
.online { color: yellow !important } // for changing text color
.offline { color: #fff !important } // for changing text color
</style>
添加一些JavaScript
<script>
$('[role=application] span:first-child').addClass('online');
$('[role=application] span:nth-child(2)').addClass('offline');
</script>
這是你的HTML
<div id="switch">
<select name="toggleswitch1" id="toggleswitch1" data-track-theme="e" data-role="slider">
<option value="off"> Offline </option>
<option value="on"> Online </option>
</select>
</div>
這裏的.ui-BTN-活躍,css中的.ui-btn-down-e類用於更改t他在不同的瀏覽器中使用背景顏色,如果需要,可以在這裏更改顏色。 javascript用於更改在線和離線的文本顏色。 這裏是示例小提琴http://jsfiddle.net/arunkumarthekkoot/95gPP/
我希望這會爲你工作。
-2
**CSS**
<style>
.green {
background: green;
}
.red {
background: red;
}
</style>
**html**
<a href="" class="green" id="btn" data-role="none">Button</a>
**Javascript**
<script>
$("#btn").on("click",function(){
if($(this).hasClass("green")){
$(this).removeClass("green");
$(this).addClass("red");
return;
}if($(this).hasClass("red")){
$(this).removeClass("red");
$(this).addClass("green");
return;
}
});
</script>
0
添加這種簡單的風格的作品對我來說:
CSS部分
.ui-slider-track .ui-btn-active {
background-color: green !important;
}
對於代碼完整性,這裏的其餘部分...
HTML部分
<label for="flipSwitch">On/Off</label>
<select name="flipSwitch" id="idFlipSwitch" data-role="slider">
<option value="on">On</option>
<option value="off">Off</option>
</select>
最後jQuery部分
$("#idFlipSwitch").val("on").slider("refresh");
相關問題
- 1. oracle窗體以編程方式更改窗口背景顏色?
- 2. 以編程方式更改列表框項目背景顏色
- 3. 如何以編程方式更改按鈕的背景顏色
- 4. Swift:以編程方式更改窗口的背景顏色
- 5. XNA以編程方式更改背景顏色
- 6. 以編程方式更改ActionBarSherlock的背景顏色
- 7. 以編程方式更改某些文本的背景顏色
- 8. 以編程方式更改背景顏色的視圖
- 9. 如何以編程方式更改對話框背景顏色?
- 10. 以編程方式更改ListView行的背景顏色(wpf)
- 11. 如何以編程方式改變背景顏色,而從iPhone
- 12. 以編程方式更改WPF可編輯組合框的背景顏色
- 13. 以編程方式更改colorControlActivated顏色
- 14. 以編程方式更改應用程序窗口小部件背景顏色
- 15. 以編程方式更改textview中某些文本的背景顏色
- 16. 更改以編程方式創建的單選按鈕的背景顏色
- 17. 以編程方式更改Android AlertDialog中的單個項目背景顏色
- 18. 以編程方式更改TableLayout中的整個列的背景顏色
- 19. 如何在iPhone SDK中以編程方式更改鍵盤的背景顏色?
- 20. 如何以編程方式更改Swift中tvOS的背景顏色?
- 21. 以編程方式使用AppCompat更改操作欄背景和文本顏色
- 22. 如何以編程方式更改繪圖資源的背景顏色
- 23. 我將如何以編程方式更改單元格的背景顏色
- 24. 如何在Xamarin中以編程方式更改導航欄的背景顏色?
- 25. 更改翻轉視圖後面的(背景?)顏色?
- 26. Contenteditable - 編輯時更改背景顏色
- 27. 更改編輯區背景顏色
- 28. 如何以正確的方式更改UITableView的背景顏色?
- 29. 當開關打開時更改UITableViewCells的背景顏色 - Swift
- 30. 更改背景顏色3
你知道爲什麼嗎?什麼是標記?其他信息會改善你的答案。 – dakab
@dakab我已經使用剩餘的部分更新了我的帖子。希望現在很清楚。 –