Servlet传递一个对象集合到jsp页面,遍历集合创建多个对应的input标签,对象的id作为input的id,如何在js中获取对应的指定的input
在页面用标签库,或者request.getAttribute("集合名称");
通过input的Id获取,使用document.getElementById("");
jsp的页面 为什么要用js拿 用EL表达式不行吗
你是如何操作获取的 是点击input要获取还是 什么不操作就要获取
第一种绑定事件使用this关键字
第二种遍历取需要的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form>
<input id="a" name="d" onblur="t(this)"/>
<input id="b" name="d"/>
<input id="c" name="d"/>
</form>
</body>
<script>
// 第一种 綁定事件
function t(obj) {
console.log(obj.id)
}
// 第二中 什麽也不操作獲取第二個文本框id 给绑定一样的名字
t1();
function t1() {
var arr = document.getElementsByName("d");
for (var i = 0; i < arr.length; i++){
console.log(arr[i].id)
}
}
</script>
</html>
运行截图