我真的是javascripting的新手...(我的网页基于jsp)我正在尝试在选择选择框中的选项时生成输入框...当用户从选择框中选择任何输入时,它会将值发送到函数 init() 并根据值生成输入框...
例如:如果
<option value="IP,OS" name="sysl"><%=sysname%></option>
被选中..那么它应该生成类似的东西
<tr>
<td> Enter IP:</td>
<td><input type="text" id="IP" name="IP"></td>
</tr>
<tr>
<td> Enter OS:</td>
<td><input type="text" id="OS" name="OS"></td>
</tr>
但是我的代码并没有生成任何...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<title>Run Batch Script</title>
<script type="text/javascript">
function init() {
document.getElementById("bname").addEventListener("change", function(){
var value = document.getElementById("bname").value; // this gives you the selected value.
var split = value.split;
var splitsize = split.length;
for (var j=0; j<splitsize; j++){
var a = "<input type = 'text' name = '" + split[j] + "' id = '" + split[j] + "'>";
document.getElementById("inputBox").innerHTML = a;
}
// Your code to add the element that you need.
}
)};
</script>
<body>
<form action="./run?host=<%=host%>&envname=<%=envname%>" method="post" name="batchForm">
<table border="0">
<tr style="font-weight: bold; font-size: 16px;">
<td>System Name: </td>
</tr>
<tr>
<td>Select Batch : </td>
<td><select id="bname" name="bname" onclicke="init()">
<%
String src = "";
String[] temp;
String loc = root + "\\" + "Temp.txt";
int c;
int tempsize;
String param;
BufferedReader S = new BufferedReader(new FileReader(loc));
ArrayList<String> list = new ArrayList<String>();
while ((src = S.readLine()) != null){
c = 3;
param = "";
temp =src.split(":");
tempsize =temp.length;
list.add(temp[0]);
if ((tempsize >2)){
int i;
for (i=2; tempsize>i ; i++){
if((temp[i].equals("null"))){
param = "";
}
else if ((i ==2) && (temp[i] != "null")){
param = temp[i];
}
else if ((i > 2)){
param = param + "," + temp[i];
}
}
}
%>
<option value="<%=param%>" name="<%=temp[0]%>"><%=temp[0]%></option>
<%
}
BatchS.close();
%>
</select></td>
</tr>
<div id = "inputBox"></div>
我做错什么了?
提前致谢!