JSP如何从另一个页面中 input的name,其实name的值为变量.

JSP如何从另一个页面中 input的name,其实name的值为变量.,第1张

楼上两位都是楼主想要的结果,其实很简单,用

Map<String,String[]> map = requestgetParameterMap();

for(String name:mapkeySet()) {

if(namestartsWith("uID")) {

String value = mapget(name)[0];

Systemoutprintln(value);

}

}

这样就行啦

1

<input type=radio name=rd1 value=1>

<input type=radio name=rd1 value=4 checked>

在jsp中获取方式就是requestgetParameter("name");

<%

String rv = requestgetParameter("rd1");

//获取的值是4,如果5个单选项一个没选,获取的值是null

%>

2,jquery本身可以未提交获取,javascript方式也算其中之一。

<s:property value="#username"/>

把“#”去掉。最重要的是,你在User类中关于name这个属性一定要有get和set方法。否则获取不到。

亲爱的。

$fnattr是获取某属性的方法。

而input原生属性有一个value,你应该获取这个value 才是这个name='b'的input的值。

用jQuery:$('inputxt')val();

语句函数:val();

假设一个input代码:

JS代码如下:

运行结果:

扩展资料:

val() 方法返回或设置被选元素的值。元素的值是通过 value 属性设置的。该方法大多用于 input 元素。如果该方法未设置参数,则返回被选元素的当前值。

使用函数设置 Value 属性的值:

$(selector)val(function(index,oldvalue))

规定返回要设置的值的函数:

index - 可选。接受选择器的 index 位置。

oldvalue - 可选。接受选择器的当前 Value 属性。

参考资料:

jquery--val()

在ajsp中,通过requestgetParameter("id")获取id值,通过requestgetParameter("name")方式获取name。

示例:

<%

 String id=(String)requestgetParameter("id");//获取到id值是8

 String id=(String)requestgetParameter("name");//获取到nane值是ab

%>

根据多选框name来获得选中的值可用如下 jquery代码实现

$("input:checkbox[name='test']:checked")each(function() { // 遍历name=test的多选框

  $(this)val();  // 每一个被选中项的值

});

实例演示:给出两组多选框,点击按钮后分别获得两组中被选择的项目

示例代码如下

创建Html元素

<div class="box">

<span>请输入用户名,限定字母、数字或下划线的组合:</span><br>

<div class="content">

<span>水果:</span><br>

<input type="checkbox" name="fruit" value="梨子"/>梨子

<input type="checkbox" name="fruit" value="李子"/>李子

<input type="checkbox" name="fruit" value="栗子"/>栗子

<input type="checkbox" name="fruit" value="荔枝"/>荔枝<br>

<span>蔬菜:</span><br>

<input type="checkbox" name="vegetable" value="青菜"/>青菜

<input type="checkbox" name="vegetable" value="萝卜"/>萝卜

<input type="checkbox" name="vegetable" value="土豆"/>土豆

<input type="checkbox" name="vegetable" value="茄子"/>茄子

</div>

<input type="button" value="提交">

</div>

设置css样式

divbox{width:300px;padding:20px;margin:20px;border:4px dashed #ccc;}

divbox span{color:#999;font-style:italic;}

divcontent{width:250px;margin:10px 0;padding:20px;border:2px solid #ff6666;}

input[type='checkbox']{margin:5px;}

input[type='button']{height:30px;margin:10px;padding:5px 10px;}

编写jquery代码

$(function(){

// 设置属性值

$("input:button")click(function() {

var fruit = "";

var vegetable = "";

$("input:checkbox[name='fruit']:checked")each(function() {

fruit += $(this)val() + " ";

});

$("input:checkbox[name='vegetable']:checked")each(function() {

vegetable += $(this)val() + " ";

});

alert("已选择水果:"+fruit+",已选择蔬菜:"+vegetable);

});

})

观察效果

以上就是关于JSP如何从另一个页面中 input的name,其实name的值为变量.全部的内容,包括:JSP如何从另一个页面中 input的name,其实name的值为变量.、jsp获取页面元素值的方法有哪些、JSP页面无法获取#user.name的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/web/9376528.html

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

发表评论

登录后才能评论

评论列表(0条)

保存