首頁 > web前端 > js教程 > 主體

單元選擇合併變色範例程式碼_jquery

WBOY
發布: 2016-05-16 16:46:59
原創
907 人瀏覽過

週末為了解答一個問題,寫了一堆程式碼,功能基本上實現,但感覺結構太差了,沒太多考慮。一點都不漂亮

複製程式碼 程式碼如下:

;


文件標題



表格{
邊框間距:0;
}
td{
高度:50px;
寬度:50px;
邊框間距:0;
}
.hidden{
顯示:無;
}
風格>
頭>



























表>


;

var selectecdlog = [];
var resultLen = 0;
var resultBegin = 0;
var backColor = ['紅色','綠色','藍色']; // 假設有3 行1 - 紅色2 - 綠色3 - 藍色
var resultColor =0;
$("td").mousedown(function() {
selectecdlog = [];
resultColor = backColor[$(this).parent().attr(' id').substr(1 )-1];
$('td').css('background-color', 'white');
// tr 標籤的ID
//alert ($(this).parent ().attr('id'));
//取得列號
//alert($(this).index() 1);
$(this ).css('背景顏色', resultColor);
selectecdlog.push($(this).attr('id'));
//alert($(this).attr('id') ); >$("td").mouseup(onMouseUp);
$("td").mouseover(onMouseOver);
})
function onMouseUp(){
/* 對事件進行操作*/
var len =resultLen= Math.abs(parseInt(selectecdlog[0].substr(selectecdlog[0].indexOf('c') 1)) - parseInt($(this).attr(' id') ).substr(($(this).attr('id').indexOf('c')) 1))) 1;
var begin =resultBegin= parseInt(selectecdlog[0].substr( selectecdlog[0].indexOf('c') 1)) >parseInt($(this).attr('id').substr(( $(this).attr('id').indexOf('c') ) 1)) ? parseInt($(this).attr('id').substr(($(this).attr('id').indexOf('c')) 1)):parseInt(selectecdlog[0].substr(selectecdlog ) [0].indexOf('c') 1));
for(var i =0; i{
selectecdlog.push(selectecdlog[0].substr(0 ,2) "c" (resultBegin i));

}
selectecdlog.shift();
$('#log').text(selectecdlog.toString());

$("td").unbind('mouseover',onMouseOver);
$("td").unbind('mouseup',onMouseUp);
}
function onMouseOver (參數參數) {
var len =resultLen= Math.abs(parseInt(selectecdlog[0].substr(selectecdlog[0].indexOf('c') 1)) - parseInt ($(this).attr('id' ).substr(($(this).attr('id').indexOf('c')) 1))) 1;
var begin =resultBegin= parseInt(selectecdlog[0].substr(selectecdlog[0 ].indexOf('c') 1)) >parseInt($(this).attr('id').substr(( $(this).attr('id').indexOf('c')) 1) ) ? parseInt($(this).attr('id').substr(($(this).attr('id').indexOf('c')) 1)):parseInt(selectecdlog[0].substr(selectecdlog ) [0].indexOf('c') 1));
$('td').css('背景顏色', '白色');
for(var i =0; i{
$('#' selectecdlog[0].substr(0,2) "c" (begin i)).css( '背景顏色', resultColor);
}
//alert( $(this).attr('id').substr(($(this).attr('id').indexOf('c')) 1));
//$ ('#' tdId).css('背景顏色', '紅色');
}
// 為每個td 設定id attr
$("td").each(function(index , val){
/* 遍歷陣列或物件*/
$ (this).attr('id', $(this).parent().attr('id') "c" ($( this).index() 1))});
//合併單元格
function merge (argument) {
// body...
for (var m in selectecdlog)
{
if(m==0)
{
$('#' selectecdlog[m]).attr('colspan', resultLen);
$('#' selectecdlog[m ]).css('width',resultLen*50 "px");
//$('#' selectecdlog[m]).css('background-color', 'bule');
}
else{
$('#' selectecdlog[m]).addClass('hidden');
}
}
}
腳本>
身體>


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!