Um eine Frage am Wochenende zu beantworten, schrieb ich eine Reihe von Code und die Funktionen wurden im Grunde genommen implementiert, aber ich hatte das Gefühl, dass die Struktur zu arm war und ich nicht viel darüber nachgedacht habe. Überhaupt nicht hübsch
Die Codekopie lautet wie folgt:
<! DocType html>
<html>
<kopf>
<title> Der Dokumenttitel </title>
<meta charset = utf-8>
<script src = "lib/jQuery-1.8.1.min.js" type = "text/javaScript"> </script>
<style type = "text/css">
Tisch{
Grenzabteilung: 0;
}
td {
Höhe: 50px;
Breite: 50px;
Grenzabteilung: 0;
}
.versteckt{
Anzeige: Keine;
}
</style>
</head>
<body>
<tabelle>
<tr id = "r1">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr id = "r2">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<p id = 'log'> </p>
<button type = "button" onclick = "combine ()"> hebing </button>
<script type = "text/javaScript">
var selectecdlog = [];
var resultlen = 0;
var resultbegin = 0;
var backcolor = ['rot', 'grün', 'blau']; // Angenommen 3 Zeilen 1 -red 2 - grün 3 - blau
var resultColor = 0;
$ ("td"). MouseDown (function () {
selectecdlog = [];
resultColor = backColor [$ (this) .Parent (). attr ('id'). substr (1) -1];
$ ('td'). CSS ('Hintergrundfarbe', 'weiß');
// ID für TR -Tag
//alert($(This).Parent().attr('id '));
// Die Spalte Nr. Holen Sie sich
//alert($(This).index()+1);
$ (this) .css ('Hintergrundfarbe', resultColor);
selectecdlog.push ($ (this) .attr ('id'));
//alert($(This).attr('id '));
$ ("TD"). MouseUp (OnmouseUp);
$ ("TD"). Mouseover (Onmouseover);
})
Funktion onmouseUp () {
/ * Auf das Ereignis handeln */
var len = resultlen = math.abs (parseInt (selectecdlog [0] .substr (selectecdlog [0] .Indexof ('c')+1)) - parseInt ($ (this) .attr ('id'). substr (($ ($) .attr ('id'). indexof ('c'))+1)+1)+1)+1)+1;
var begin = resultBegin = parseInt (selectecdlog [0] .substr (selectEcDlog [0] .Indexof ('c')+1)> parseInt ($ (this) .attr ('id'). substr (($ ($) .Attr ('id'). indexof ('c'))+1)? parseInt ($ (this) .attr ('id'). substr (($ (this) .attr ('id'). indexof ('c'))+1));
für (var i = 0; i <resultlen; 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);
}
Funktion onmouseover (Argument) {
var len = resultlen = math.abs (parseInt (selectecdlog [0] .substr (selectecdlog [0] .Indexof ('c')+1)) - parseInt ($ (this) .attr ('id'). substr (($ ($) .attr ('id'). indexof ('c'))+1)+1)+1)+1)+1;
var begin = resultBegin = parseInt (selectecdlog [0] .substr (selectEcDlog [0] .Indexof ('c')+1)> parseInt ($ (this) .attr ('id'). substr (($ ($) .Attr ('id'). indexof ('c'))+1)? parseInt ($ (this) .attr ('id'). substr (($ (this) .attr ('id'). indexof ('c'))+1));
$ ('td'). CSS ('Hintergrundfarbe', 'weiß');
für (var i = 0; i <len; i ++)
{
$ ('#'+selectecdlog [0] .Substr (0,2)+"C"+(begin+i)). CSS ('Hintergrund-Color', resultColor);
}
// alert ($ (this) .attr ('id'). substr (($ (this) .Attr ('id'). indexof ('c'))+1));
//$('#'+TDID).css('background-color ',' rot ');
}
// ID ATT für jeden TD einstellen
$ ("td"). Jede (Funktion (Index, Val) {
/ * durch Array oder Objekt iterieren */
$ (this) .attr ('id', $ (this) .Parent (). attr ('id')+"c"+($ (this) .Index ()+1))});
// Zellen kombinieren
Funktion kombinieren (Argument) {
// Körper...
für (var m in SelectEcDlog))
{
if (m == 0)
{
$ ('#'+selectecdlog [m]). attr ('colspan', resultlen);
$ ('#'+selectecdlog [m]). CSS ('width', resultlen*50+"px");
//$('#'+ Selectecdlog AppocdLog · M]).css('background-Color ',' Bule ');
}
anders{
$ ('#'+selectecdlog [m]). AddClass ('Hidden');
}
}
}
</script>
</body>
</Html>