Home > front end >  JQuery recently learned a couple of days, wrote a operating table web pages, and ajax can directly u
JQuery recently learned a couple of days, wrote a operating table web pages, and ajax can directly u

Time:11-19

Recently, watch the video tutorials, qian feng Web front-end speak quite good, spend a little bit of time, by reference, modify, wrote a fun
Share with everyone, there is need to improve after hope you can modify, back to a post thank you
Qian feng Web front-end under the special thanks to the teacher!

Click on the first column ID is selected, click the other grid programming editable state, click the blanks, cancel the editor state
[/code]


 
/* *
* the jQuery timers - Timer abstractions for jQuery
* Written by Blair Mitchelmore (Blair DOT Mitchelmore AT gmail DOT com)
* Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
* the Date: 2009/02/08
*
* @ author Blair Mitchelmore
* @ version 1.1.2
*
* */

JQuery. Fn. The extend ({
EveryTime: function (interval, label, fn, times, belay) {
Return this. Each (function () {
JQuery. The timer. The add (this interval, label, fn, times, belay);
});
},
OneTime: function (interval, label, fn) {
Return this. Each (function () {
JQuery. The timer. The add (this interval, label, fn, 1);
});
},
StopTime: function (label, fn) {
Return this. Each (function () {
JQuery. The timer. Remove (this, label, fn);
});
}
});

JQuery. Event. Special

JQuery. The extend ({
The timer: {
Global: [],
Guid: 1,
DataKey: "jQuery. The timer,"
Regex:/^ ([0-9] + (? : \ [0-9] *)? S \ s * (. *)? $/,
Powers: {
//Yeah this is major overkill...
"Ms" : 1,
"Cs" : 10,
"Ds" : 100,
's: 1000,
"Das" : 10000,
'the hs: 100000,
"Ks" : 1000000
},
TimeParse: function (value) {
If (value=https://bbs.csdn.net/topics/=undefined | | value==null)
return null;
Var result.=this regex. Exec (jQuery. Trim (value. The toString ()));
If (result [2]) {
Var num=parseFloat (the result of [1]).
Var mult=this. Powers [the result of [2]] | | 1;
Return num * mult;
} else {
return value;
}
},
Add: function (element, the interval, label, fn, times, belay) {
Var counter=0;

{if (jQuery. IsFunction (label))
if (! Times)
Times=fn;
Fn=label;
Label=interval;
}

The interval=jQuery. The timer. TimeParse (interval);

If (typeof interval!='number' | | isNaN (interval) | | interval & lt;=0)
return;

If (times & amp; & Times. The constructor!=Number) {
Belay=!!!!! Times;
Times=0;
}

Times=times | | 0;
Belay=belay | | false;

Var timers=jQuery. Data (element, enclosing dataKey) | | jQuery. The data (element, enclosing dataKey, {});

if (! Timers [label])
Timers (label)={};

Fn. TimerID=fn. TimerID | | this. Guid++;

Var handler=function () {
If (belay & amp; & Enclosing inProgress)
return;
Enclosing inProgress=true;
If ((+ + counter & gt; Times & amp; & Times!==0) | | fn. Call (element, counter)===false)
JQuery. The timer. Remove (element, label, fn);
Enclosing inProgress=false;
};

Handler. TimerID=fn. TimerID;

if (! Timers [label] [fn timerID])
Timers [label] [fn timerID]=window. The setInterval (handler, the interval);

This. Global. Push (element);

},
Remove: function (element, label, fn) {
Var timers=jQuery. Data (element, enclosing dataKey), ret.

If (timers) {

if (! Label) {
For (label in timers)
This. Remove (element, label, fn);
{} else if (timers [label])
If (fn) {
If (fn) timerID) {
Window. ClearInterval (timers [label] [fn. TimerID]);
Delete timers [label] [fn timerID];
}
} else {
For (var fn timers in [label]) {
Window. ClearInterval (timers [label] [fn]);
The delete timers [label] [fn];
}
}

For (ret timers in [label]) break;
If (! Ret) {
Ret=null;
The delete timers (label);
}
}

For (ret in timers) break;
If (! Ret)
JQuery. RemoveData (element, enclosing dataKey);
}
}
}
});

JQuery (window). Bind (" unload ", function () {
JQuery. Each (jQuery. The timer. Global, function index, the item () {
JQuery. The timer. Remove (item);
});
});


 



<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "/& gt;
<script SRC="https://libs.baidu.com/jquery/1.10.2/jquery.min.js" & gt; </script>
<script SRC="https://bbs.csdn.net/topics/jquery_timer.js" & gt; </script>
<style>
Table
{
Border - the collapse: the collapse;
Border - spacing: 0;
margin-right: auto;
Margin - left: auto;
Width: 800 px;
Margin - top: 5 px;
}
Th, td
{
Border: # 1 px solid b5d6e6;
font-size: 12px;
font-weight: normal;
text-align: center;
vertical-align: middle;
Height: 25 px;
}
Th {background - color: Gray; }
The hover {background - color: # cccc00; }
The odd {background - color: # BBF; }
. Even {background - color: # FFC; }
The sel {background - color: red; }

Div {text - align: center; Margin: 0 px; }
</style>
  • Related