JQuery 小練習(xí)(實(shí)例代碼)
更新時(shí)間:2009年08月07日 22:52:20 作者:
空閑時(shí)候?qū)懙囊恍﹋query小代碼,雖然就幾分鐘完成的小代碼,但每天保持練習(xí),不至于頭腦會(huì)生銹;
1、按鈕倒數(shù)10秒之后才能點(diǎn)擊。這個(gè)效果一般在一些論壇注冊(cè)時(shí)候用到比較多,廢話少說,直接上代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
var timeOut;
var count = 10;
$(function() {
$("#btnSubmit").attr("disabled", "disabled");
$("#btnSubmit").val("確(" + count.toString() + ")定");
timeOut = setTimeout(ButtonCount, 1000);
});
ButtonCount = function() {
if (count == 0) {
$("#btnSubmit").attr("disabled", "");
$("#btnSubmit").val("確 定");
clearTimeout(timeOut);
}
else {
count--;
$("#btnSubmit").attr("disabled", "disabled");
$("#btnSubmit").val("確(" + count.toString() + ")定");
setTimeout(ButtonCount, 1000);
}
}
</script>
</head>
<body>
<input type="button" value="確 定" id="btnSubmit" />
</body>
</html>
2、即點(diǎn)即改,這個(gè)效果一個(gè)多月前還沒有學(xué)jquery時(shí)覺得好酷,現(xiàn)在覺得其實(shí)也非常簡(jiǎn)單的東西,可以看出jquery在前端效果上大大簡(jiǎn)化了編寫難度,代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
.caneditBg
{
background-color:Gray;
}
</style>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$(".canedit").each(function() {
$(this).bind("dblclick", function() {
var html = $(this).html();
var textarea = "<textarea name='temTextarea' id='temTextarea' onblur='saveText(this)' >" + html + "</textarea>";
$(this).empty().html(textarea);
});
$(this).mouseenter(function() { $(this).addClass("caneditBg") }).mouseleave(function() { $(this).removeClass("caneditBg") });
});
});
saveText = function(o) {
var text = $(o).val();
$(o).parent().empty().html(text);
}
</script>
</head>
<body>
<div class="canedit">
即點(diǎn)即改!
</div>
<div>
</div>
</body>
</html>
以上代碼只需要直接copy到html文件,并且保證導(dǎo)入jquery.js文件無錯(cuò),就可以運(yùn)行。
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
var timeOut;
var count = 10;
$(function() {
$("#btnSubmit").attr("disabled", "disabled");
$("#btnSubmit").val("確(" + count.toString() + ")定");
timeOut = setTimeout(ButtonCount, 1000);
});
ButtonCount = function() {
if (count == 0) {
$("#btnSubmit").attr("disabled", "");
$("#btnSubmit").val("確 定");
clearTimeout(timeOut);
}
else {
count--;
$("#btnSubmit").attr("disabled", "disabled");
$("#btnSubmit").val("確(" + count.toString() + ")定");
setTimeout(ButtonCount, 1000);
}
}
</script>
</head>
<body>
<input type="button" value="確 定" id="btnSubmit" />
</body>
</html>
2、即點(diǎn)即改,這個(gè)效果一個(gè)多月前還沒有學(xué)jquery時(shí)覺得好酷,現(xiàn)在覺得其實(shí)也非常簡(jiǎn)單的東西,可以看出jquery在前端效果上大大簡(jiǎn)化了編寫難度,代碼如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
.caneditBg
{
background-color:Gray;
}
</style>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$(".canedit").each(function() {
$(this).bind("dblclick", function() {
var html = $(this).html();
var textarea = "<textarea name='temTextarea' id='temTextarea' onblur='saveText(this)' >" + html + "</textarea>";
$(this).empty().html(textarea);
});
$(this).mouseenter(function() { $(this).addClass("caneditBg") }).mouseleave(function() { $(this).removeClass("caneditBg") });
});
});
saveText = function(o) {
var text = $(o).val();
$(o).parent().empty().html(text);
}
</script>
</head>
<body>
<div class="canedit">
即點(diǎn)即改!
</div>
<div>
</div>
</body>
</html>
以上代碼只需要直接copy到html文件,并且保證導(dǎo)入jquery.js文件無錯(cuò),就可以運(yùn)行。
相關(guān)文章
Ext.get() 和 Ext.query()組合使用實(shí)現(xiàn)最靈活的取元素方式
想要利用ExtJS的庫函數(shù)對(duì)DOM進(jìn)行各類操作,就要得到Element類型的對(duì)象,但是Ext.get()取到的雖然是Element,但是參數(shù)只能是id,如果大家對(duì)jQuery的selector方式很喜歡和崇拜,那么就一定要學(xué)習(xí)Ext.get()和Ext.query()的組合方式。2011-09-09jQuery實(shí)現(xiàn) 上升、下降、刪除、添加一行代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn) 上升、下降、刪除、添加一行代碼的實(shí)現(xiàn)方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03jQuery在header中設(shè)置請(qǐng)求信息的方法
這篇文章主要介紹了jQuery在header中設(shè)置請(qǐng)求信息的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03jQuery中fadeIn、fadeOut、fadeTo的使用方法(圖片顯示與隱藏)
jQuery中fadeIn、fadeOut、fadeTo的使用方法(圖片顯示與隱藏),需要的朋友可以參考一下2013-05-05jquery仿百度百科底部浮動(dòng)導(dǎo)航特效
這篇文章主要介紹了jquery仿百度百科底部浮動(dòng)導(dǎo)航特效,需要的朋友可以參考下2015-08-08