Re: [問題] javascript 表格變色寫在function裡
建議可以用jquery插件的方式來做
jquery插件部分:
/*
* 用來定義table內的行數變色使用
*/
(function($) {
$.fn.extend({showColor: function(){
$(this).hover(function() {
tmp_color = $(this).css('background-color'); //保留原來tr的顏色
$(this).css('background-color','#FFD300'); //變換tr顏色
}, function() {
$(this).css('background-color',tmp_color); //還原tr顏色
});
}});
})(jQuery);
網頁部分:
<script src="jquery.js" type="text/javascript" ></script>
<script src="jquery.tablecolor.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(e){
$("table tr").showColor();
});
</script>
這樣可以比較容易管理
網頁碼也可以縮短點
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.249.3.87
→
10/09 20:25, , 1F
10/09 20:25, 1F
推
10/10 16:30, , 2F
10/10 16:30, 2F
→
10/10 16:31, , 3F
10/10 16:31, 3F
→
10/10 18:12, , 4F
10/10 18:12, 4F
→
10/10 18:14, , 5F
10/10 18:14, 5F
→
10/12 10:44, , 6F
10/12 10:44, 6F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):