封装html的select标签的js操作实例
时间:2024-05-09 10:34:07
function BindSelect(id,dataList,fieldtext,fieldValue) {
//绑定某一个数据源,fieldtext为需要绑定的文本字段,fieldValue为需要绑定的value字段
var select = $("#" + id)[0];
for (var i = 0; i < dataList.length; i++) {
select.options.add(new Option(eval("dataList[" + i + "]." + fieldtext), eval("dataList[" + i + "]." + fieldValue)));
}
}
function BindSelectOptions(id, OptionList) {
var select = $("#" + id)[0];
for (var i = 0; i < OptionList.length; i++) {
select.options.add(new Option(OptionList[i].Text, OptionList[i].Value));
}
}
function ClearAllItems(id) {//清空所有的选项
var select = $("#" + id)[0];
select.options.length = 0;
}
function AddOneItem(id, text, value) {//添加一个选项
var select = $("#" + id)[0];
select.options.add(new Option(text, value));
}
function selectOneOption(id, selectValue) {//根据值,选中一个选项
var select = $("#" + id)[0];
var len = select.options.length;
for (var i = 0; i < len; i++) {
if (select.options[i].value == selectValue) {
select.options[i].selected = true;
break;
}
}
}
function selectOneOptionByIndex(id, index) {//<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">//根据下标,选中一个选项</SPAN>
var select = $("#" + id)[0];
var len = select.options.length;
if (index >= 0 && index <= len) {
select.options[index].selected = true;
}
}
标签:封装,html,select标签
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python读写txt文本文件的操作方法全解析
2021-08-07 04:06:20
![](https://img.aspxhome.com/file/2023/4/112574_0s.png)
HTML 5 正在改变 Web
2008-09-15 08:20:00
![](https://img.aspxhome.com/file/UploadPic/20089/15/20089158232273s.jpg)
python+selenium+autoit实现文件上传功能
2021-01-16 12:00:04
![](https://img.aspxhome.com/file/2023/2/117362_0s.jpg)
Python 通过截图匹配原图中的位置(opencv)实例
2021-10-06 02:04:44
![](https://img.aspxhome.com/file/2023/4/63924_0s.jpg)
Python实现的特征提取操作示例
2023-02-07 06:08:04
Pygame 精准检测图像碰撞的问题
2022-01-17 17:56:13
对python中不同模块(函数、类、变量)的调用详解
2022-01-17 14:36:38
SQL SERVER 分组求和sql语句
2024-01-13 04:43:16
![](https://img.aspxhome.com/file/2023/7/94407_0s.png)
jquery实用技巧之输入框提示语句
2024-04-22 12:49:10
![](https://img.aspxhome.com/file/2023/1/136091_0s.jpg)
python使用pynput库操作、监控你的鼠标和键盘
2022-04-18 00:24:38
![](https://img.aspxhome.com/file/2023/3/124793_0s.png)
python实现银行账户系统
2023-05-27 17:49:08
![](https://img.aspxhome.com/file/2023/0/103340_0s.jpg)
利用python GDAL库读写geotiff格式的遥感影像方法
2023-08-31 13:15:06
python 机器学习之支持向量机非线性回归SVR模型
2022-06-17 20:23:55
![](https://img.aspxhome.com/file/2023/1/75941_0s.png)
Python实现找到同名文件并复制到其他文件夹中
2022-03-16 21:53:14
![](https://img.aspxhome.com/file/2023/8/113138_0s.png)
谈谈设计师的发展
2009-03-17 18:20:00
Python中getpass模块无回显输入源码解析
2022-05-02 03:58:28
Python如何通过手肘法实现k_means聚类详解
2021-03-13 16:35:34
![](https://img.aspxhome.com/file/2023/4/127724_0s.png)
W3C优质网页小贴士(一)
2008-04-06 16:35:00
![](https://img.aspxhome.com/file/UploadPic/up/2008040712541063.gif)
Python爬虫抓取手机APP的传输数据
2021-10-04 03:26:51
![](https://img.aspxhome.com/file/2023/8/87968_0s.png)
如何在Django中设置定时任务的方法示例
2023-03-21 06:19:07