jquery 使用點(diǎn)滴函數(shù)代碼
更新時(shí)間:2011年05月20日 01:30:47 作者:
簡(jiǎn)單的按鈕js事件 用于判斷和顯示提示
1、簡(jiǎn)單的按鈕js事件 用于判斷和顯示提示
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#btnlogin").click(function () {
$("#lblInfo").html("");
var uid = $.trim($("#txtUsername").val());
var pwd = $.trim($("#txtPassword").val());
if (uid == "") {
$("#lblInfo").html("賬號(hào)不能為空");
$("#txtUsername").focus();
return false;
}
if (pwd == "") {
$("#lblInfo").html("密碼不能為空");
$("#txtPassword").focus();
return false;
}
});
});
</script>
2、下拉列表的處理
function dropTypeChange()
{
var sel = $("#<%=dropType.ClientID %> option:selected").val();
if(sel=="-1")
{
$("#<%=txtNo.ClientID %>").attr('disabled',true);
}
else
{
$("#<%=txtNo.ClientID %>").attr('disabled',false);
}
}
//獲取第一個(gè)option的值
$('#test option:first').val();
//最后一個(gè)option的值
$('#test option:last').val();
//獲取第二個(gè)option的值
$('#test option:eq(1)').val();
//獲取選中的值
$('#test').val();
$('#test option:selected').val();
//設(shè)置值為2的option為選中狀態(tài)
$('#test').attr('value','2');
//設(shè)置第一個(gè)option為選中
$('#test option:last').attr('selected','selected');
$("#test").attr('value' , $('#test option:last').val());
$("#test").attr('value' , $('#test option').eq($('#test option').length - 1).val());
//獲取select的長(zhǎng)度
$('#test option').length;
//添加一個(gè)option
$("#test").append("<option value='9'>ff</option>");
$("<option value='9'>ff</option>").appendTo("#test");
//添除選中項(xiàng)
$('#test option:selected').remove();
//指定項(xiàng)選中
$('#test option:first').remove();
//指定值被刪除
$('#test option').each(function(){
if( $(this).val() == '5'){
$(this).remove();
}
});
$('#test option[value=5]').remove();
//獲取第一個(gè)Group的標(biāo)簽
$('#test optgroup:eq(0)').attr('label');
//獲取第二group下面第一個(gè)option的值
$('#test optgroup:eq(1) :option:eq(0)').val();
復(fù)制代碼 代碼如下:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#btnlogin").click(function () {
$("#lblInfo").html("");
var uid = $.trim($("#txtUsername").val());
var pwd = $.trim($("#txtPassword").val());
if (uid == "") {
$("#lblInfo").html("賬號(hào)不能為空");
$("#txtUsername").focus();
return false;
}
if (pwd == "") {
$("#lblInfo").html("密碼不能為空");
$("#txtPassword").focus();
return false;
}
});
});
</script>
2、下拉列表的處理
復(fù)制代碼 代碼如下:
function dropTypeChange()
{
var sel = $("#<%=dropType.ClientID %> option:selected").val();
if(sel=="-1")
{
$("#<%=txtNo.ClientID %>").attr('disabled',true);
}
else
{
$("#<%=txtNo.ClientID %>").attr('disabled',false);
}
}
//獲取第一個(gè)option的值
$('#test option:first').val();
//最后一個(gè)option的值
$('#test option:last').val();
//獲取第二個(gè)option的值
$('#test option:eq(1)').val();
//獲取選中的值
$('#test').val();
$('#test option:selected').val();
//設(shè)置值為2的option為選中狀態(tài)
$('#test').attr('value','2');
//設(shè)置第一個(gè)option為選中
$('#test option:last').attr('selected','selected');
$("#test").attr('value' , $('#test option:last').val());
$("#test").attr('value' , $('#test option').eq($('#test option').length - 1).val());
//獲取select的長(zhǎng)度
$('#test option').length;
//添加一個(gè)option
$("#test").append("<option value='9'>ff</option>");
$("<option value='9'>ff</option>").appendTo("#test");
//添除選中項(xiàng)
$('#test option:selected').remove();
//指定項(xiàng)選中
$('#test option:first').remove();
//指定值被刪除
$('#test option').each(function(){
if( $(this).val() == '5'){
$(this).remove();
}
});
$('#test option[value=5]').remove();
//獲取第一個(gè)Group的標(biāo)簽
$('#test optgroup:eq(0)').attr('label');
//獲取第二group下面第一個(gè)option的值
$('#test optgroup:eq(1) :option:eq(0)').val();
相關(guān)文章
jquery 觸發(fā)a鏈接點(diǎn)擊事件解決方案
使用jquery為a連接綁定點(diǎn)擊事件,具體代碼如下,感興趣的朋友可以參考下,希望可以幫助到你2013-05-05
牛叉的Jquery——Jquery與DOM對(duì)象的互相轉(zhuǎn)換及DOM的三種操作
Jquery對(duì)象就是通過(guò)jQuery包裝DOM對(duì)象后產(chǎn)生的對(duì)象,jQuery對(duì)象是jQuery獨(dú)有的,其可以使用jQuery里的方法,本文給大家介紹Jquery對(duì)象就是通過(guò)jQuery包裝DOM對(duì)象后產(chǎn)生的對(duì)象,jQuery對(duì)象是jQuery獨(dú)有的,其可以使用jQuery里的方法。感興趣的朋友可以參考下2015-10-10
用jquery實(shí)現(xiàn)動(dòng)畫跳到頂部和底部(這個(gè)比較簡(jiǎn)單)
用jquery實(shí)現(xiàn)動(dòng)畫的跳到頂部和底部,當(dāng)點(diǎn)擊頂部按鈕的時(shí)候,執(zhí)行方法,scrollTop屬性獲取選中標(biāo)簽距滾動(dòng)條的距離2014-09-09
jQuery獲取頁(yè)面元素絕對(duì)與相對(duì)位置的方法
這篇文章主要介紹了jQuery獲取頁(yè)面元素絕對(duì)與相對(duì)位置的方法,涉及jQuery中offset、position等方法的使用技巧,需要的朋友可以參考下2015-06-06
ASP.NET jQuery 實(shí)例5 (顯示CheckBoxList成員選中的內(nèi)容)
這章我們主要看下如何通過(guò)jQuery來(lái)獲取CheckBoxList成員內(nèi)容2012-01-01
基于jQuery Circlr插件實(shí)現(xiàn)產(chǎn)品圖片360度旋轉(zhuǎn)
Circlr是一款可以對(duì)產(chǎn)品圖片進(jìn)行360度全方位旋轉(zhuǎn)展示的jQuery插件,本文給大家分享一款基于jQuery Circlr插件實(shí)現(xiàn)產(chǎn)品圖片360度旋轉(zhuǎn),大家一起來(lái)看看吧2015-09-09

