JSP中如何获取select标签选中的值

JSP中如何获取select标签选中的值,第1张

今天写代码遇到一个问题,在jsp页面中通过form的得到的select标签的值,form提交给自身页面,然后通过requestgetParameter()方法取得值测试代码如下(文件名为:testselectjsp): My JSP 'testselectjsp' starting page 通过requestgetParameter("number")方法取得下拉框选取的值 运行界面:

("#select1 option:selected")attr("定义的属性");

如果属性定义的是data-xxx,那么直接

("#select1 option:selected")data("xxx");

<div id="sel" style="display: none">

<select name="select2">

<option value="1" selected>采购部</option>

<option value="2">生产部</option>

<option value="3">库存部</option>

</select>

</div>

<div id="in" style="display: none">

<input type="text" name="userInfo" class="logininput" id="name" size="25">

</div>

<select name="select" onchange=myselect()>

<option value="department" selected>用户部门</option>

<option value="userName">用户姓名</option>

</select>

在JavaScript块里定义这个函数:

function myselect(){

//selectedIndex == 0 表示选了:用户部门

if(documentforms[form1]select[0]selectedIndex == 0){

documentgetElementById('sel')styledisplay = "";

documentgetElementById('in')styledisplay = "none";

return;

}

//selectedIndex == 0 表示选了:用户姓名

if(documentforms[form1]select[0]selectedIndex == 1){

documentgetElementById('in')styledisplay = "";

documentgetElementById('sel')styledisplay = "none";

return;

}

}

这样应该就可以了,是手写的,不知道有没有拼错,楼主有问题可以M我!!

JQuery是控制和 *** 作select详解。

先看下面的html代码

<select id="test">

<option value="1">选项一<option>

<option value="2">选项一<option>

<option value="n">选项N<option>

</select>

所谓jQuery *** 作“select”, 说的更确切一些是应该是jQuery控制 “option”, 看下面的jQuery代码:

//获取第一个option的值

$('#test option:first')val();

//最后一个option的值

$('#test option:last')val();

//获取第二个option的值

$('#test option:eq(1)')val();

//获取选中的值

$('#test')val();

$('#test option:selected')val();

//设置值为2的option为选中状态

$('#test')attr('value','2');

//设置最后一个option为选中

$('#test option:last')attr('selected','selected');

$("#test")attr('value' , $('#test option:last')val());

$("#test")attr('value' , $('#test option')eq($('#test option')length - 1)val());

//获取select的长度

$('#test option')length;

//添加一个option

$("#test")append("<option value='n+1'>第N+1项</option>");

$("<option value='n+1'>第N+1项</option>")appendTo("#test");

//添除选中项

$('#test option:selected')remove();

//删除项选中(这里删除第一项)

$('#test option:first')remove();、

//指定值被删除

$('#test option')each(function(){

if( $(this)val() == '5'){

$(this)remove();

}

});

$('#test option[value=5]')remove();

//获取第一个Group的标签

$('#test optgroup:eq(0)')attr('label');

//获取第二group下面第一个option的值

$('#test optgroup:eq(1) : option:eq(0)')val();

以上就是关于JSP中如何获取select标签选中的值全部的内容,包括:JSP中如何获取select标签选中的值、Jquery怎么获取select选中项 自定义属性的值、JSP怎样获取当前页select值并作为后面判断条件等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9339356.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存