国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jquery select操作的日期聯動實現代碼

2024-05-06 14:12:30
字體:
來源:轉載
供稿:網友
Jquery的選擇器很強大,對select的options對象添加的時候我找了老半天才找到
代碼如下:
/**//*
文件名:jquery.liu.select.js
功能說明:本js文件為jquery類庫的一個插件,主要實現對select的操作.
作者:John Liu
編寫日期:2008/03/12
*/
//得到select項的個數
jQuery.fn.size = function()
{
return jQuery(this).get(0).options.length;
}
//獲得選中項的索引
jQuery.fn.getSelectedIndex = function()
{
return jQuery(this).get(0).selectedIndex;
}
//獲得當前選中項的文本
jQuery.fn.getSelectedText = function()
{
if(this.size() == 0)
{
return "下拉框中無選項";
}
else
{
var index = this.getSelectedIndex();
return jQuery(this).get(0).options[index].text;
}
}
//獲得當前選中項的值
jQuery.fn.getSelectedValue = function()
{
if(this.size() == 0)
{
return "下拉框中無選中值";
}
else
{
return jQuery(this).val();
}
}
//設置select中值為value的項為選中
jQuery.fn.setSelectedValue = function(value)
{
jQuery(this).get(0).value = value;
}
//設置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("下拉框中不存在該項");
}
}
//設置選中指定索引項
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中添加一項,顯示內容為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)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 湘潭县| 丹寨县| 札达县| 新安县| 闽清县| 安康市| 新闻| 奉化市| 桂东县| 方山县| 睢宁县| 锦屏县| 临朐县| 苍溪县| 阆中市| 安宁市| 尼玛县| 绥江县| 安仁县| 乌鲁木齐县| 措美县| 黑水县| 万山特区| 翁源县| 齐齐哈尔市| 永年县| 始兴县| 班玛县| 胶南市| 松江区| 麻栗坡县| 海晏县| 金塔县| 玛纳斯县| 德惠市| 鹤山市| 汉川市| 沧州市| 瓮安县| 宁化县| 江山市|