资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

jquery下拉列表,js下拉列表

jquery下拉列表选择问题

!DOCTYPE HTML

创新互联公司是一家专业的成都网站建设公司,我们专注网站设计、网站建设、网络营销、企业网站建设,外链一元广告为企业客户提供一站式建站解决方案,能带给客户新的互联网理念。从网站结构的规划UI设计到用户体验提高,创新互联力求做到尽善尽美。

html lang="en-US"

head

meta charset="UTF-8"

titlemenu/title

style type="text/css"

/style

script type="text/javascript" src="jquery-1.8.0.min.js"/script

script type="text/javascript"

$ (function ()

{

$ (":radio").change (function ()

{

$("select:first").val($(this).val());

$("select:first").triggerHandler('change');

});

$("select:first").change (function ()

{

var index = $(this).children("option:selected").index();

if (index == 1)

{

$("select:last option:nth-child(2n+1)").prop("selected", false);

$("select:last option:nth-child(2n)").prop("selected", true);

}

else

{

$("select:last option:nth-child(2n)").prop("selected", false);

$("select:last option:nth-child(2n+1)").prop("selected", true);

}

})

})

/script

/head

body

table

tr

td*资质版本/td

tdlabelinput type="radio" name="version" value="old" /旧版 /label labelinput type="radio" name="version" value="new" /新版 /label

/td

/tr

tr

td*行业分类/td

tdselect multiple="multiple"

option value="old"旧版/option

option value="new"新版/option

/select select multiple="multiple"

option建设工程企业资质标准/option

option工程设计企业资质标准/option

option工程勘察企业资质标准/option

option工程监理企业资质标准/option

/select

button搜索分类/button/td

/tr

/table

/body

/html

如何用jquery制作下拉列表

使用jQuery配合Superfish制作下拉菜单需要具备以下几个参数 1、项目中需要有jQuery版本库; 2、下载Superfish插件——Superfish; 3.需要把上面两个js引入你的项目中 导入jQuery库和Superfish插件 为了让菜单一个默认的样式

如何获取下拉列表选中的值 jquery

分别使用javascript原生的方法和jquery方法

select id="test" name=""

option value="1"text1/option

option value="2"text2/option

/select

code:

一:javascript原生的方法

1:拿到select对象: var myselect=document.getElementById("test");

2:拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index

3:拿到选中项options的value: myselect.options[index].value;

4:拿到选中项options的text: myselect.options[index].text;

二:jquery方法(前提是已经加载了jquery库)

1:var options=$("#test option:selected"); //获取选中的项

2:alert(options.val()); //拿到选中项的值

3:alert(options.text()); //拿到选中项的文本

jquery怎么设置下拉列表被选中

参考以下两种方法:

设置option的selected属性为true

设置select标签的value值为需要选中的值

实例演示如下:

1、根据演示需要,给出一个示例HTML结构

select id="test"

option value="1"option-1/option

option value="2"option-2/option

option value="3"option-3/option

/selectbr

input type="button" id="btn1" value="设置option-2选中"

input type="button" id="btn2" value="设置value=3的项选中"

2、jquery代码

$(function(){

// 方法1:设置option的selected属性为true

$("#btn1").click(function() {  // 第一个按钮单击事件

$("select option").each(function() { // 遍历所有option,如果option内容为option-2,就设置起selected属性为true

if($(this).text()=="option-2")

$(this).prop("selected",true);

});

});

// 方法2:设置select标签的value值为需要选中的值

$("#btn2").click(function() { // 第二个按钮的单击事件

$("select").val("3");  // 设置option值为3的选项选中

});

});

3、效果演示


新闻标题:jquery下拉列表,js下拉列表
文章链接:http://cdkjz.cn/article/hooeid.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220