SELECT控件操作的JS代码示例
SELECT控件操作的JS代码示例
1 检测是否有选中
if(objSelect.selectedIndex > -1) {
//说明选中
} else {
//说明没有选中
}
2.动态创建select
function createSelect(){
var mySelect = document.createElement_x("select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
}
3.添加选项option
function addOption(){
//根据id查找对象,
var obj=document.getElementByIdx('mySelect');
//添加一个选项
obj.add(new Option("文本","值"));
}
4.删除所有选项option
function removeAll(){
var obj=document.getElementByIdx('mySelect');
obj.options.length=0;
}
5.删除一个选项option
function removeOne(){
var obj=document.getElementByIdx('mySelect');
//index,要删除选项的序号,这里取当前选中选项的序号
var index=obj.selectedIndex;
obj.options.remove(index);
}
6.获得选项option的值
var obj=document.getElementByIdx('mySelect');
var index=obj.selectedIndex; //序号,取当前选中选项的序号
var val = obj.options[index].value;
7.获得选项option的文本
var obj=document.getElementByIdx('mySelect');
var index=obj.selectedIndex; //序号,取当前选中选项的序号
var val = obj.options[index].text;
8.修改选项option
var obj=document.getElementByIdx('mySelect');
var index=obj.selectedIndex; //序号,取当前选中选项的序号
var val = obj.options[index]=new Option("新文本","新值");
9.删除select
function removeSelect(){
var mySelect = document.getElementByIdx("mySelect");
mySelect.parentNode.removeChild(mySelect);
}
一、基础理解:
var e = document.getElementByIdx("selectId");
e.options = new Option("文本", "值"); //创建一个option对象
,即在标签中创建一个或多个。options是一个数组,里面可存放多个标签。
1、options数组的属性: length -------长度属性 selectedIndex ------ 当前被选中的文本的索引值,此索引值是内存自动分配的(0,1,2,3....)对应(第一个文本值,第二个文本值,第三个文本值,第四个文本值.......)
2、单个option的属性(即obj.options[obj.selectedIndex]是指定的某个
全选" onclick="choiceAll('left')"> 未选择
全选" onclick="choiceAll('right')">
<SELECTmultiple="multiple"[J1] style="width:200px" size="20" id="left" > 添加" onclick="move('left','right')" style="background: #deb887;">
删除>>" onclick="move('right','left')" style="background:#ffebcd;"> <SELECTmultiple="multiple" style="width:200px" size="20" id="right" >
SELECT控件操作的JS代码示例的更多相关文章
- 日历控件修改的JS代码
var bMoveable=true; var _VersionInfo=" " ; //============================================= ...
- selenium中元素操作之浏览器窗口滚动&网页日期控件操作(js操作)(五)
js的滚动条scrollIntoView() Arguments[] - python与js之间的羁绊 1.移动到元素element对象的“底端”,与当前窗口的“底部”对齐: driver.execu ...
- jquery实现页面控件拖动效果js代码
;(function($) { var DragPanelId = "divContext"; var _idiffx = 0; var _idiffy = 0; var _Div ...
- 基于vue.js实现远程请求json的select控件
基本思路 前端把需要的参数类型编码传到后台,后台返回相应的参数列表json,前端利用vue渲染select控件 具体实现 前端代码 <select v-model="template. ...
- js操作select控件大全(包含新增、修改、删除、选中、清空、判断存在等)
原文:js操作select控件大全(包含新增.修改.删除.选中.清空.判断存在等) js操作select控件大全(包含新增.修改.删除.选中.清空.判断存在等) js 代码// 1.判断select选 ...
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件 【转】http://www.cnblogs.com/lxblog/archive/2013/01/09/2853056.html
Jquery 操作Html 控件 CheckBox.Radio.Select 控件 在使用 Javascript 编写前台脚本的时候,经常会操作 Html 控件,比如 checkbox.radio ...
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
在使用 Javascript 编写前台脚本的时候,经常会操作 Html 控件,比如 checkbox.radio.select,用 Jquery 库操作其他会方便很多,下面用Jq对这些控件的操作进行一 ...
- js+CSS实现模拟华丽的select控件下拉菜单效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html select控件的jq操作
html select控件的jq操作 1.判断select选项中 是否存在Value="paraValue"的Item $("#selectid option[@valu ...
随机推荐
- Jquery设置Cookie
jQuery代码: <script src="js/jquery-1.3.1.js" type="text/javascript"></scr ...
- js字符串和正则表达式中的match、replace、exec等的配合使用
正则并不是经常使用,而正则和字符串之间的函数关系又错综复杂,谁是谁的函数,又是怎么样的一种结果,往往我们是看一遍忘一遍,对此我是头疼不已,感觉自己是个笨蛋^_^. 为了以后不再查文档,特此把常用的函数 ...
- img标签 加载FTP的图片 C#
好吧,我是菜鸟,这是我今天遇到的问题,什么也不会,得高人指点 1.使用FtpWebRequest下载图片,以流存贮 2.在ashx文件里面直接已流方式(HttpContext.Current.Resp ...
- 无边框窗体和timer控件
一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要放置的控件可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入(pictureBox1_MouseE ...
- bcd-ascii相互转换函数
// BCD转ASCII int Asc2Bcd(unsigned char *input, unsigned int inputLen, unsigned char *output) { unsig ...
- Jquery做点击选中与鼠标移上特效
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- json转类
JavaScriptSerializer js = new JavaScriptSerializer();T detaile = js.Deserialize<T>(json);
- jQuery设置聚焦并使光标位置在文字最后
var editor = document.getElementById('btn'); editor.onfocus = function () { window.setTimeout(functi ...
- ReportingService报表入门
今天我们来学习一下ReportingService报表的制作. ReportingService是微软提供的一个制作报表的工具,它集成在Microsoft Visual Studio中. 启动Visu ...
- CentOS安装crontab及使用方法(汇总多人博客并实践确认无误)
安装centOS: yum -y install vixie-cron --该软件包是cron的主程序 yum -y install crontabs--该软件包用来安装.卸载或者列举需要cron来守 ...