代码如下:var sel=document.getElementById(id);//select元素的id var index=sel.selectedIndex;//获取被选中的option的索引 var textsel= sel.options[index].text;//获取相应的option的内容
很多时候,美工会觉得默认的select下拉框很难看(特别是右侧的下拉箭头按钮),他们通常喜欢用一个自定义的图标来代替这个按钮。这样就只能用 js + div 来模拟了,倒腾了一番,用jQuery模拟了下,当然网上这种文章也不少,只是懒得去看找 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>...
代码如下:$(document).ready(function(){ $("#precinct").change(function(){ $("#ptype").val("");//重置所有 $("#stype").html(""); $("#stype").append("<option value=\"\">--请选择--</option>"); }); <span style="white-space:pre"> </span>//监听专利类型change事件 $("#ptype").change(function(){ var ptype = $(this); var atype = $(this).val();//对象值 var pid = $("#precinct").val(); if (!ptype.data(atype)) {/...
jQuery有一个很好用的delegate(事件委派)功能,可以给当前以及将来(动态添加)的元素绑定一个事件处理函数。 比如下面的例子,动态添加一个输入文本框后,我想让所有文本框(不管是不是动态添加的)在获取焦点时,自动转大写。 代码如下:<!doctype html><html><head> <title>delegate测试</title> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.js"></script> <style type="text/css">...
将input、select清空 代码如下:var inputObjs=jQuery("#queryAdvancedDiv input[type=text]"); for(var i=0;i<inputObjs.length;i++){ var inputObj = inputObjs[i]; inputObj.value=""; } var selectObjs = jQuery("#queryAdvancedDiv select"); for(var i=0;i<selectObjs.length;i++){ var selectObj = selectObjs[i]; selectObj.value=""; }
如下所示: 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript">function copyToList(from,to){ var fromList=eval(document.forms[0].+from); var t...
jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text 3. var checkValue=$("#select_id").val(); //获取Select选择的Value 4. var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值 5. var maxIndex=$("#se...
1、js代码: 代码如下:function init() { document.getElementById("studyPhase").disabled=true; } 2、h:selectOneMenu下拉框 代码如下:<h:selectOneMenu id="studyPhase" value="#{schoolfellowInfoEdit.studyPhase}" > <f:selectItems value="#{schoolfellowInfoEdit.studyPhaseNamesItems}"/> </h:selectOneMenu>
代码如下:var obj = document.getElementByIdx_x(”testSelect”); //定位idvar index = obj.selectedIndex; // 选中索引var text = obj.options[index].text; // 选中文本var value = obj.options[index].value; // 选中值jQuery中获得选中select值第一种方式$(#testSelect option:selected).text();//选中的文本$(#testSelect option:selected) .val();//选中的值$("#testSelect ").get(0).selectedIndex;//索引 第二种方式$("#t...
jsp代码: 代码如下:<form id="search"> <select id="jobSelect" style="width: 200px;" name="jobSelect"> <s:if test='jobSelect == null || jobSelect == ""'> <option selected="selected" value="-1">--依职类筛选--</option> </s:if> <s:else> <option value="-1">--依职类筛选--</option> </s:else> <s:iterator value="jobCat" status="s"> <s:if test="jobSelect == catKey"> <option value="<s:property v...
本篇文章提供一款jquery遍历select教程代码,主要是利用了$("#<%=ddl_xreg_id.clientid%> option").each(function() {形式来each遍历一次,这样所有的select就给查询了一次。 代码如下:<script src="jquery-1.2.1.js" type="text/网页特效"></script><script language="javascript" type="text/javascript">$(document).ready(function(){$("#selecttest").change(function(){ //alert("hello"); //alert($("#selectte...
1.jQuery添加/删除Select的Option项:2.$("#select_id").append("<option value=Value>Text</option>"); //为Select追加一个Option(下拉项) 3.$("#select_id").prepend("<option value=0>请选择</option>"); //为Select插入一个Option(第一个位置) 4.$("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个) 5.$("#select_id option[index=0]").remove(); //删除Select中索引值为0的Option(第...
HTML代码: 代码如下:<select id="month" onchange="selectInput(this)"> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08" selected="selected">August</option> <o...
1.动态创建select 代码如下: function createSelect(){ var mySelect = document.createElement_x("select"); mySelect.id = "mySelect"; document.body.appendChild(mySelect); }2.添加选项option 代码如下: function addOption(){ //根据id查找对象, var obj=document.getElementByIdx_x(mySelect); //添加一个选项obj.add(new Option("文本","值")); //这个...
代码如下:function getSelectedText() { //this function code is borrowed from: http://www.codetoad.com/javascript_get_selected_text.asp var txt = ""; if (window.getSelection) { txt = window.getSelection(); } else if (window.document.getSelection) { txt = window.document.getSelection(); } else if (window.document.selection) { txt = window.document.selection.createRange().text; } return txt; }