jQuery中Form相關(guān)知識(shí)匯總
form中的單行文本獲取和失去焦點(diǎn)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript" src="../../js/jquery-2.1.3.js"></script>
<title></title>
<style type="text/css">
input:focus, textarea:focus {
border: 1px solid#f00;
background: #fcc;
}
.focus {
border: 1px solid#f00;
background: #fcc;
}
</style>
</head>
<body>
<form action="#" method="post" id="regForm">
<fieldset>
<legend>個(gè)人基本信息</legend>
<div>
<label for="username">名稱:</label>
<input id="username" type="text">
</div>
<div>
<label for="pass">密碼:</label>
<input id="pass" type="password">
</div>
<div>
<label for="msg">詳細(xì)信息:</label>
<textarea id="msg"></textarea>
</div>
</fieldset>
</form>
</body>
<script type="text/javascript">
/**
* 1.單行文本框---得到焦點(diǎn)和失去焦點(diǎn)
* */
$(function () {
$(":input").focus(function () {
$(this).addClass("focus");
}).blur(function () {
$(this).removeClass("focus");
})
})
</script>
</html>
更改多行文本的高度
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript" src="../../js/jquery-2.1.3.js"></script>
<title></title>
<style type="text/css">
* { margin:0; padding:0;font:normal 12px/17px Arial; }
.msg {width:300px; margin:100px; }
.msg_caption { width:100%; overflow:hidden; margin-bottom:1px;}
.msg_caption span { display:block; float:left; margin:0 2px; padding:4px 10px; background:#898989; cursor:pointer;color:white; }
.msg textarea{ width:300px; height:80px;height:100px;border:1px solid #000;}
</style>
</head>
<body>
<form>
<div class="msg">
<div class="msg_caption">
<span class="bigger">放大</span>
<span class="smaller">縮小</span>
</div>
<textarea id="comment" rows="8" cols="20">多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
</textarea>
</div>
</form>
</body>
<script type="text/javascript">
/**
* 多行文本框的高度調(diào)整
* */
$(function () {
var $comment = $('#comment');
$('.bigger').click(function () {
if(!$comment.is(":animated")) {
if($comment.height() < 500) {
//$comment.height($comment.height() + 50);//版本1
$comment.animate({height: "+=50"}, 400);
}
}
});
$('.smaller').click(function () {
if(!$comment.is(":animated")) {
if($comment.height() > 50) {
//$comment.height($comment.height() - 50);
$comment.animate({height: "-=50"}, 400);
}
}
});
});
</script>
</html>
更改多行文本的滾動(dòng)條高度
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript" src="../../js/jquery-2.1.3.js"></script>
<title></title>
<style type="text/css">
* { margin:0; padding:0;font:normal 12px/17px Arial; }
.msg {width:300px; margin:100px; }
.msg_caption { width:100%; overflow:hidden; margin-bottom:1px;}
.msg_caption span { display:block; float:left; margin:0 2px; padding:4px 10px; background:#898989; cursor:pointer;color:white; }
.msg textarea{ width:300px; height:80px;height:100px;border:1px solid #000;}
</style>
</head>
<body>
<form>
<div class="msg">
<div class="msg_caption">
<span class="up">向上</span>
<span class="down">向下</span>
</div>
<textarea id="comment" rows="8" cols="20">多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。多行文本框高度變化。
</textarea>
</div>
</form>
</body>
<script type="text/javascript">
/**
* 多行文本框的滾動(dòng)條高度調(diào)整
* */
$(function () {
var $comment = $('#comment');
$('.up').click(function () {
if(!$comment.is(":animated")) {
if($comment.height() < 500) {
$comment.animate({scrollTop: "+=50"}, 400);
}
}
});
$('.down').click(function () {
if(!$comment.is(":animated")) {
if($comment.height() > 50) {
$comment.animate({scrollTop: "-=50"}, 400);
}
}
});
});
</script>
</html>
復(fù)選框應(yīng)用
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript" src="../../js/jquery-2.1.3.js"></script>
<title></title>
<style type="text/css">
input:focus, textarea:focus {
border: 1px solid#f00;
background: #fcc;
}
.focus {
border: 1px solid#f00;
background: #fcc;
}
</style>
</head>
<body>
<form>
你愛好的運(yùn)動(dòng)是?<br/>
<input type="checkbox" name="items" value="足球"/>足球
<input type="checkbox" name="items" value="籃球"/>籃球
<input type="checkbox" name="items" value="羽毛球"/>羽毛球
<input type="checkbox" name="items" value="乒乓球"/>乒乓球
<input type="button" id="checkedAll" value="全 選"/>
<input type="button" id="checkedNo" value="全不選"/>
<input type="button" id="checkedRev" value="反 選"/>
<input type="button" id="send" value="提交"/>
</form>
</body>
<script type="text/javascript">
/**
* 復(fù)選框應(yīng)用
* */
$(function () {
$("#checkedAll").click(function () {
$('[name=items]:checkbox').attr('checked', true);
});
$("#checkedNo").click(function () {
$('[name=items]:checkbox').attr('checked', false);
});
$("#checkedRev").click(function () {
$('[name=items]:checkbox').each(function () {
this.checked = !this.checked;
});
});
$("#send").click(function () {
var str = "你選中的是: \r\n";
$('[name=items]:checkbox:checked').each(function () {
str += $(this).val() + "\r\n";
});
alert(str);
});
})
</script>
</html>
- jquery EasyUI的formatter格式化函數(shù)代碼
- jQuery EasyUI API 中文文檔 - Form表單
- jquery表單驗(yàn)證使用插件formValidator
- jQuery實(shí)現(xiàn)form表單reset按鈕重置清空表單功能
- jQuery-serialize()輸出序列化form表單值的方法
- jquery實(shí)現(xiàn)ajax提交form表單的方法總結(jié)
- jquery序列化form表單使用ajax提交后處理返回的json數(shù)據(jù)
- jquery form 加載數(shù)據(jù)示例
- jquery動(dòng)態(tài)改變form屬性提交表單
- jquery中$(#form :input)與$(#form input)的區(qū)別
相關(guān)文章
jQuery中Ajax全局事件引用方式及各個(gè)事件(全局/局部)執(zhí)行順序
這篇文章主要介紹了jQuery中Ajax全局事件引用方式及各個(gè)事件(全局/局部)執(zhí)行順序的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-06-06PHP+jQuery實(shí)現(xiàn)隨意拖動(dòng)層并即時(shí)保存拖動(dòng)位置
本文講解了如何采用PHP+MySQL+jQuery,實(shí)現(xiàn)隨意拖動(dòng)層并即時(shí)保存拖動(dòng)位置。 十分的實(shí)用,有需要的小伙伴可以參考下。2015-04-04Eclipse配置Javascript開發(fā)環(huán)境圖文教程
這篇文章主要介紹了Eclipse配置Javascript開發(fā)環(huán)境圖文教程,需要的朋友可以參考下2015-01-01jQuery通過deferred對(duì)象管理ajax異步
這篇文章主要介紹了jQuery通過deferred對(duì)象管理ajax異步的相關(guān)資料,需要的朋友可以參考下2016-05-05jquery js 重置表單 reset()具體實(shí)現(xiàn)代碼
我們希望表單提交以后,能reset,由于jquery沒有這個(gè)方法,所以只能采用其他的方法來實(shí)現(xiàn)了,具體如下,有此需求的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08jQuery.Highcharts.js繪制柱狀圖餅狀圖曲線圖
這篇文章主要介紹了jQuery.Highcharts.js繪制柱狀圖餅狀圖曲線圖的方法,非常的實(shí)用,小伙伴們可以直接拿到項(xiàng)目中使用。2015-03-03jquery根據(jù)name取得select選中的值實(shí)例(超簡單)
下面小編就為大家分享一篇jquery根據(jù)name取得select選中的值實(shí)例(超簡單),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01