国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看
打開APP
未登錄
開通VIP,暢享免費電子書等14項超值服
開通VIP
首頁
好書
留言交流
下載APP
聯(lián)系客服
jquery操作select
WindySky
>《jquery》
2011.08.21
關(guān)注
//得到select項的個數(shù)
jQuery.fn.size = function(){
return
jQuery(
this
).get(
0
).options.length;
}
//獲得選中項的索引
jQuery.fn.getSelectedIndex = function(){
return
jQuery(
this
).get(
0
).selectedIndex;
}
//獲得當(dāng)前選中項的文本
jQuery.fn.getSelectedText = function(){
if
(
this
.size() ==
0
)
return
"下拉框中無選項"
;
else
{
var index =
this
.getSelectedIndex();
return
jQuery(
this
).get(
0
).options[index].text;
}
}
//獲得當(dāng)前選中項的值
jQuery.fn.getSelectedValue = function(){
if
(
this
.size() ==
0
)
return
"下拉框中無選中值"
;
else
return
jQuery(
this
).val();
}
//設(shè)置select中值為value的項為選中
jQuery.fn.setSelectedValue = function(value){
jQuery(
this
).get(
0
).value = value;
}
//設(shè)置select中文本為text的第一項被選中
jQuery.fn.setSelectedText = function(text)
{
var isExist =
false
;
var count =
this
.size();
for
(var i=
0
;i<count;i++)
{
if
(jQuery(
this
).get(
0
).options[i].text == text)
{
jQuery(
this
).get(
0
).options[i].selected =
true
;
isExist =
true
;
break
;
}
}
if
(!isExist)
{
alert(
"下拉框中不存在該項"
);
}
}
//設(shè)置選中指定索引項
jQuery.fn.setSelectedIndex = function(index)
{
var count =
this
.size();
if
(index >= count || index <
0
)
{
alert(
"選中項索引超出范圍"
);
}
else
{
jQuery(
this
).get(
0
).selectedIndex = index;
}
}
//判斷select項中是否存在值為value的項
jQuery.fn.isExistItem = function(value)
{
var isExist =
false
;
var count =
this
.size();
for
(var i=
0
;i<count;i++)
{
if
(jQuery(
this
).get(
0
).options[i].value == value)
{
isExist =
true
;
break
;
}
}
return
isExist;
}
//向select中添加一項,顯示內(nèi)容為text,值為value,如果該項值已存在,則提示
jQuery.fn.addOption = function(text,value)
{
if
(
this
.isExistItem(value))
{
alert(
"待添加項的值已存在"
);
}
else
{
jQuery(
this
).get(
0
).options.add(
new
Option(text,value));
}
}
//刪除select中值為value的項,如果該項不存在,則提示
jQuery.fn.removeItem = function(value)
{
if
(
this
.isExistItem(value))
{
var count =
this
.size();
for
(var i=
0
;i<count;i++)
{
if
(jQuery(
this
).get(
0
).options[i].value == value)
{
jQuery(
this
).get(
0
).remove(i);
break
;
}
}
}
else
{
alert(
"待刪除的項不存在!"
);
}
}
//刪除select中指定索引的項
jQuery.fn.removeIndex = function(index)
{
var count =
this
.size();
if
(index >= count || index <
0
)
{
alert(
"待刪除項索引超出范圍"
);
}
else
{
jQuery(
this
).get(
0
).remove(index);
}
}
//刪除select中選定的項
jQuery.fn.removeSelected = function()
{
var index =
this
.getSelectedIndex();
this
.removeIndex(index);
}
//清除select中的所有項
jQuery.fn.clearAll = function()
{
jQuery(
this
).get(
0
).options.length =
0
;
}
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報
。
打開APP,閱讀全文并永久保存
查看更多類似文章
猜你喜歡
類似文章
jquery的each()詳細介紹
jquery 將json對象賦值給form表單
jquery 獲取頁面url,并根據(jù)url模擬單擊事件
css(name|pro|[,val|fn]) | jQuery API 1.12 中文文檔 | jQuery API 在線手冊
我最喜歡的jQuery插件模板
js常用方法之事件注冊
更多類似文章 >>
生活服務(wù)
首頁
萬象
文化
人生
生活
健康
教育
職場
理財
娛樂
藝術(shù)
上網(wǎng)
留言交流
回頂部
聯(lián)系我們
分享
收藏
點擊這里,查看已保存的文章
導(dǎo)長圖
關(guān)注
一鍵復(fù)制
下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!
聯(lián)系客服
微信登錄中...
請勿關(guān)閉此頁面
先別劃走!
送你5元優(yōu)惠券,購買VIP限時立減!
5
元
優(yōu)惠券
優(yōu)惠券還有
10:00
過期
馬上使用
×