<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>TEST INPUT</title>
<script type="text/javascript">
function setValue() {
x = document.getElementById('id3');
x.value = "sad";
//document.write(x.id);
}
function setValue1() {
x = document.getElementsByName('second');
x[0].value = "sad";
//document.write(x.id);
}
</script>
</head>
<body>
<%
String a = "happy";
%>
input的属性设置:
<br>
<%
for (int i = 0; i < 5; i++) {
%>
<input type="text" name="first<%=i + ""%>" value="<%=a%> everyday"
id="id<%=i + ""%>">
<input type="text" name="second" value="<%=a%> everyday"
id="id<%=i + ""%>">
<br>
<%
}
%>
<input type="button" value="button" οnclick="setValue()">
<input type="button" value="button1" οnclick="setValue1()">
</body>
</html>
浏览器访问结果:
点击前:
点击后: