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...
本系列文章分为:基本篇、层次篇、简单篇、内容篇、可见性篇、属性篇、子元素篇、表单篇、表单对象属性篇共9篇文章。 您对本系列文章有任何建议或意见请发送到邮箱:sjzlgt@qq.com 由于是第一次写技术性系列文章,难免会出错或代码BUG,欢迎指出,在此谢过! 在线地址 http://demo.jb51.net/html/jquery/jQuery-Selectors-2-bynet.htmjQuery-Selectors-2-bynet .div { width:95%; margin-left:15px; margin-top:15px; margin-righ...
function move(formObj,toObj){ if(formObj.selectedIndex != -1){ toObj.add(new Option(formObj.options[formObj.selectedIndex].text,formObj.options[formObj.selectedIndex].value)); formObj.remove(formObj.selectedIndex); //var index = formObj.selectedIndex; } } [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
我的学习方法:先入门,后进阶!本系列文章分为:基本篇、层次篇、简单篇、内容篇、可见性篇、属性篇、子元素篇、表单篇、表单对象属性篇共9篇文章。详细介绍页面 http://demo.jb51.net/html/jquery/jQuery-Selector.htmljQuery-Selectors .div { width:95%; margin-left:15px; margin-top:15px; margin-right:15px; padding-left:5px; padding-top:5px; padding-bottom:5px; background-color:#ccc; border:#999 1px solid; lin...
js select /*移除左边选中的列表项到右边*/ function fMoveSelectedOptionsLeftToRight(oLeft,oRight) { if(!(oLeft&&oRight)) { return; } if(!hasOptions(oLeft)) { return; } if(oLeft.selectedIndex==-1) { oLeft.selectedIndex=0; } for(var i=0;i0) { oSelect.remove(ops.length-1); } } } /*清空select所有选中的options*/ function clearSelectedOptions(oSelect) { if(oSelect) { for(var i=0;...
本系列文章分为:基本篇、层次篇、简单篇、内容篇、可见性篇、属性篇、子元素篇、表单篇、表单对象属性篇共9篇文章。 本篇讲解:[attribute],[attribute=value],[attribute!=value],[attribute^=value],[attribute$=value],[attribute*=value],[selector1][selector2][selectorN]的用法。 您对本系列文章有任何建议或意见请发送到邮箱:sjzlgt@qq.com 由于是第一次写技术性系列文章,难免会出错或代码BUG,欢迎指出,在此谢过! 运...
1.判断select选项中 是否存在value="paravalue"的item2.向select选项中 加入一个item3.从select选项中 删除一个item4.修改select选项中 value="paravalue"的text为"paratext"5.设置select中text="paratext"的第一个item为选中6.设置select中value="paravalue"的item为选中7.得到select的当前选中项的value8.得到select的当前选中项的text9.得到select的当前选中项的index10.清空select的项---------------------------------------...
本系列文章分为:基本篇、层次篇、简单篇、内容篇、可见性篇、属性篇、子元素篇、表单篇、表单对象属性篇共9篇文章。 本篇讲解::enabled,:disabled,:checked,:selected的用法。 您对本系列文章有任何建议或意见请发送到邮箱:sjzlgt@qq.com 由于是第一次写技术性系列文章,难免会出错或代码BUG,欢迎指出,在此谢过! 运行后,需要刷新下,加载下jqueryjQuery-Selectors-9 .div { width:95%; margin-left:15px; margin-top:15px;...
本系列文章分为:基本篇、层次篇、简单篇、内容篇、可见性篇、属性篇、子元素篇、表单篇、表单对象属性篇共9篇文章。 本篇讲解::nth-child(index/even/odd/equation),:first-child,:last-child,:only-child的用法。 您对本系列文章有任何建议或意见请发送到邮箱:sjzlgt@qq.com 由于是第一次写技术性系列文章,难免会出错或代码BUG,欢迎指出,在此谢过! 您可以到jQuery官网来学习更多的有关jQuery知识。 运行后,请刷新下,因为...
代码如下:funtion setSelectOption(a,b){//a =>select 的id名,b=>已知option的值 for (i=0;i<$(a).length;i++) //$(a)获取a的id的简单写法,前提是必须用引用prototype.js if($(a).options[i].value == b){//遍历select $(a).options[i].selected=true;//选中特定值 break; }
一、 插入option 1、DOM方法 var oSelectYear = document.getElementById("SelectYear"); var op = document.createElement("option"); op.innerHTML = "2010"; op.value = "2010"; oSelectYear.appendChild(op); 2、new Option方法 var oSelectMonth = document.getElementById("SelectMonth"); oSelectMonth.options.add(new Option(1, 1)); oSelectMonth.options.add(new Option(2, 2)); 二、 清空option var oSelectMonth = do...
获取Select : 获取select 选中的 text : $("#ddlRegType").find("option:selected").text(); 获取select选中的 value: $("#ddlRegType ").val(); 获取select选中的索引: $("#ddlRegType ").get(0).selectedIndex; 设置select: 设置select 选中的索引: $("#ddlRegType ").get(0).selectedIndex=index;//index为索引值 设置select 选中的value: $("#ddlRegType ").attr("value","Normal“); $("#ddlRegType ").val("Normal"); $("...
删除select中重复项 body{ text-align:center;} div{ width:400px; background:#f1f5fa; margin:auto; border:solid 1px #BFC9DB; padding:10px;} h4{ } a{text-align:right; display:block; font-size:12px;} /*定义全局函数$*/ function $(id){ return document.getElementById(id); } /*初始化select*/ function InitialSelectOption(id){ var oSel=$(id); var aOptions=["Wang Hongjian","Wang Hongjian","Nichoal S...
代码如下: function opts(selectObj){ var optDivs=document.createElement("div"); var objTable=document.createElement("table"); var objTbody=document.createElement("tbody"); optDivs.style.zIndex = "100"; objTable.style.zIndex = "100"; objTa...
于是就测试了下: 代码如下: var stringToDom=function(text) { var doc; if(window.ActiveXObject) { doc = new ActiveXObject("MSXML2.DOMDocument"); doc.loadXML(text).documentElement; } else { doc = (new DOMParser()).parseFromString(text,"text/xml"); } return doc; } var xmlDoc=stringToDom("ab"), c, d1=new Date(); for(var i=0;i<100000;i++){ c=xmlDoc.getElementsByTagName("a"); } document.write("getElemen...