function addTest(){
document.getElementById("add").innerHTML+="
商品品牌:<select id='s1' name='brand[]'>
<option></option>
</select>
商品类别:<select id='s2' name='class[]'>
<option></option>
</select>商品货号:<input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数量:<input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价:<input type=text name=danjia[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /><br />";
}
html代码:<a onClick="addTest()"><font style="cursor:hand;" color="#0033CC">添加商品</font></a> <br />商品品牌:<select id="s1" name="brand[]">
<option></option>
</select>
商品类别:<select id="s2" name="class[]">
<option></option>
</select>
商品货号:<input type="text" name="shop_item[]" style=" width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;" />
数量:<input type="text" name="shop_count[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>
单价:<input type="text" name="danjia[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>商品品牌:<select id="s1" name="brand[]">
<option></option>
</select>
商品类别:<select id="s2" name="class[]">
<option></option>
</select>
商品货号:<input type="text" name="shop_item[]" style=" width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;" />
数量:<input type="text" name="shop_count[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>
单价:<input type="text" name="danjia[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>请问,为什么我在javascript里面放上下拉列表就会报错?拿出来就没事呢?
document.getElementById("add").innerHTML+="
商品品牌:<select id='s1' name='brand[]'>
<option></option>
</select>
商品类别:<select id='s2' name='class[]'>
<option></option>
</select>商品货号:<input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数量:<input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价:<input type=text name=danjia[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /><br />";
}
html代码:<a onClick="addTest()"><font style="cursor:hand;" color="#0033CC">添加商品</font></a> <br />商品品牌:<select id="s1" name="brand[]">
<option></option>
</select>
商品类别:<select id="s2" name="class[]">
<option></option>
</select>
商品货号:<input type="text" name="shop_item[]" style=" width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;" />
数量:<input type="text" name="shop_count[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>
单价:<input type="text" name="danjia[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>商品品牌:<select id="s1" name="brand[]">
<option></option>
</select>
商品类别:<select id="s2" name="class[]">
<option></option>
</select>
商品货号:<input type="text" name="shop_item[]" style=" width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;" />
数量:<input type="text" name="shop_count[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>
单价:<input type="text" name="danjia[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>请问,为什么我在javascript里面放上下拉列表就会报错?拿出来就没事呢?
解决方案 »
- com.microsoft.sqlserver.jdbc.SQLServerException : 该语句已关闭
- 菜鸟问个小问题
- 移植web程序遇到不断弹出的警告,无从下手
- 关于打开/admin/index.jsp 找不到useBean的问题
- 在jsp页面点击某一列,对表进行正序排序,再点击实现倒序排序-与分页不能共同实现
- 每次刷新页面都提示说要安装该activex插件
- 问个关于SESSION的问题。。
- 为什么我用getParameter取到的是null
- 分钟计时器。。在线等
- 请问有那位朋友了解JSP开发语言及其相关开发站点?
- 我的商业网站开放服务平台上线了,大家给我点意见!
- WEB-INF下可不可以放框架集,可以的话应如何访问到!已经是第三贴了!帮忙@ @!
<option> </option>
</select>
商品类别: <select id="s2" name="class[]">
<option> </option>
</select>
将这个放到
function addTest(){
document.getElementById("add").innerHTML+="
商品品牌: <select id='s1' name='brand[]'>
<option> </option>
</select>
商品类别: <select id='s2' name='class[]'>
<option> </option>
</select>商品品牌: <select id="s1" name="brand[]">
<option> </option>
</select>
商品类别: <select id="s2" name="class[]">
<option> </option>
</select> 商品货号: <input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数量: <input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价: <input type=text name=danjia[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> <br />";
} 就会报错。这个怎么弄呀??
document.getElementById("add").innerHTML+=" 商品品牌: <select id='s1' name='brand[]'>
<option> </option>
</select>
商品类别: <select id='s2' name='class[]'>
<option> </option>
</select>商品品牌: <select id="s1" name="brand[]">
<option> </option>
</select>
商品类别: <select id="s2" name="class[]">
<option> </option>
</select> 商品货号: <input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数量: <input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价: <input type=text name=danjia[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> <br />";
} 这里有的呀、、、
报错信息是什么啊!!
<option></option>
</select>
商品类别:<select id='s2' name='class[]'>
<option></option>
我上面用的是单引号的。只不过复制错了。。不好意思、报错:一个是:缺少对象,一个是:未结束的字符串常量
我刚才试试
你那样是不行的。试试这样吧, 例如:
var s = "商品品牌: <select id=\"s1\" name=\"brand[]\"> <option> </option> </select> ";
var p = "商品类别: <select id=\"s2\" name=\"class[]\"><option> </option> </select> ";
document.getElementById("add").innerHTML +=" <h1>fd5saf1sa1f561sdf1</h1>" + s + p;注意啊! 上面我的在编辑器里面能在一行放下, 你要在一行放下 可以多用几个变量 试试!
我的可以
你那样点击 网页有错误!
页面初始化是s1和s2两个,并且load了change方法,但是add新加的时候没有给他方法,且id要改变,如:添加一个就id变成了s3和s4;
我稍微改了下,可能不太多,稍微改下应该就可以了;
function addTest(){
var n = s.length;
var s1 = "s"+(n+1);
var s2 = "s"+(n+2);
s[n] = s1;
s[n+1] = s2;
document.getElementById("add").innerHTML+="内容省略了,是我改过的那个内容";
for(var i=n;i<s.length-1;i++) {
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
}
change(0); //不知道是不是还是0
}
在点击<a onClick="addTest()"> <font style="cursor:hand;" color="#0033CC">添加商品 </font> </a> <br />
它的时候,在页面上就会增加这么几个:
function addTest(){
document.getElementById("add").innerHTML+="商品品牌:<select id='s1[i]' name='brand[]'><option></option></select>商品类别:<select id='s2[i]' name='class[]'><option></option></select>商品货号:<input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数量:<input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价:<input type=text name=danjia[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /><br />";
}
其中包括,商品品牌、商品类别、数量、单价在页面上就会添加这个。。
我在EditPlus 下运行的<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script> function addTest(){
document.getElementById("info").innerHTML+="商品品牌: <select id='s1[i]' name='brand[]'> <option>123 </option> </select>商品类别: <select id='s2[i]' name='class[]'> <option> 3123</option> </select>商品货号: <input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数量: <input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价: <input type=text name=danjia[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> <br />";
}
</script>
</HEAD>
<body >
<form id="form1">
<table>
<input type="checkbox" name="myChkbox" />check
<br>
name:<input name="input1" value="">
<br>
<input type="button" value="submit" class="" onclick="mySubmit();" >
<a onclick="addTest();"> <font style="cursor:hand;" color="#0033CC">添加商品 </font> </a> <br >
<div id="info"> </div>
</table>
</form>
</body>
</HTML>
下拉框应该是一样的<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function getValue(){
alert(document.getElementsByName("danjia")[0].value)}
function addTest(){
document.getElementById("info").innerHTML+="商品品牌: <select id='s1[i]' name='brand'> <option>123 </option> </select>商品类别: <select id='s2[i]' name='class[]'> <option> 3123</option> </select>商品货号: <input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数量: <input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> 单价: <input type=text id=test name=danjia style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /> <br />";
}
</script>
</HEAD>
<body >
<form id="form1">
<table>
<input type="checkbox" name="myChkbox" />check
<br>
name:<input name="input1" value="">
<br>
<input type="button" value="submit" class="" onclick="getValue();" > <a onclick="addTest();"> <font style="cursor:hand;" color="#0033CC">添加商品 </font> </a> <br >
<div id="info"> </div>
</table>
</form>
</body>
</HTML>
然后 document.getElementsByName可以取到一个数组对象然后根据这个数组去取值就可以了
document.getElementsByName("danjia")[0].value
这个index 可以用一个循环得到
for(i=0;i<document.getElementsByName("danjia").length;i++)
alert(document.getElementsByName("danjia")[i].value)应该没有问题了把