有大侠知道 怎么限制 最多可以添加20个文本框吗?
知道的麻烦帮帮忙
JS+html<script language="javascript">
function add()
{
option = new Array();
proportion = new Array();
str='<table>';
str=str+'<tr align=center valign=middle bgcolor=#FFFFFF>';
str=str+'<td width="100%" height="25"><input type="text" name=proportion></td>';
str=str+'<td width="100%" height="25"><input type="button" name=del onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)" value="删除"></td>';
str=str+'</tr></table>';
window.upid.innerHTML+=str+'';
}
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="myform" onsubmit="javascript:return check()">
<table>
<tr>
<td>
<input name="Submit2" type="button" onclick="javascript:add()" value="增加">
</td>
</tr>
<tr>
<td>
<div id="upid"></div>
</td>
</tr>
</table>
</form>
</body>
</html>
知道的麻烦帮帮忙
JS+html<script language="javascript">
function add()
{
option = new Array();
proportion = new Array();
str='<table>';
str=str+'<tr align=center valign=middle bgcolor=#FFFFFF>';
str=str+'<td width="100%" height="25"><input type="text" name=proportion></td>';
str=str+'<td width="100%" height="25"><input type="button" name=del onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)" value="删除"></td>';
str=str+'</tr></table>';
window.upid.innerHTML+=str+'';
}
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="myform" onsubmit="javascript:return check()">
<table>
<tr>
<td>
<input name="Submit2" type="button" onclick="javascript:add()" value="增加">
</td>
</tr>
<tr>
<td>
<div id="upid"></div>
</td>
</tr>
</table>
</form>
</body>
</html>
解决方案 »
- 利用JS如何获取JW player播放停止或者是当前播放时间
- 送分~求一简单的JS TAB切换效果
- 服务企业为Linux时,InetAddress.getLocalHost().getHostAddress()为何得到为127.0.0.1?
- xmlHttp.responseText是字符串吗?
- <script language="JavaScript" src="http://www.google.cn"></script>-----语法错误
- Javascript 动态加载文件域上传文件 无法提交
- 用open打开新窗口时怎么实现传回值?在线等
- 如何使用javascript实现一个在线编辑功能的textarea呢?
- 小问题帮忙啦
- 真可惜:GOOGLE.COM不能用了
- 客户端事件如何触发服务器端行为(如何通过javascript实现点击客户端浏览器打印按钮触发服务器端对数据库的修改?)
- 请教大家一个获取文字的问题
function add()
{
var tables=window.upid.innerHTML.getElementsByTagName("TABLE")
if(tables.length>19)
return;
}
function add()
{
if(getLength()==20)
return;
//继续操作}function getLength(){
var texts=document.getElementsByTagName("input");
var inputlength=0;
for( var i=0;i<texts.length;i++){
if(texts[i].type="text")
inputlength++;
}
return inputlength;
}
<script language="javascript">
var i=0;
function add()
if(i>=19){return false;}
{
option = new Array();
proportion = new Array();
str=' <table>';
str=str+' <tr align=center valign=middle bgcolor=#FFFFFF>';
str=str+' <td width="100%" height="25"> <input type="text" name=proportion> </td>';
str=str+' <td width="100%" height="25"> <input type="button" name=del onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)" value="删除"> </td>';
str=str+' </tr> </table>';
i++;
window.upid.innerHTML+=str+'';
}
</script>
<td>
<div id="upid"> </div>
</td>window.upid是取上面id为upid的div块吗?,学习了!
var count=0;
function add()
{
if(count<20)
{
option = new Array();
proportion = new Array();
str=' <table>';
str=str+' <tr align=center valign=middle bgcolor=#FFFFFF>';
str=str+' <td width="100%" height="25"> <input type="text" name=proportion value=这是第:'+(count+1)+'个> </td>';
str=str+' <td width="100%" height="25"> <input type="button" name=del onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex);count--" value="删除"> </td>';
str=str+' </tr> </table>';
window.upid.innerHTML+=str+'';
count++;
}
}
</script>
<html>
<head>
<title>Untitled Document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="myform" onsubmit="javascript:return check()">
<table>
<tr>
<td>
<input name="Submit2" type="button" onclick="javascript:add()" value="增加">
</td>
</tr>
<tr>
<td>
<div id="upid"> </div>
</td>
</tr>
</table>
</form>
</body>
</html>
2 给table定义一个id,通过getElementById的方式获得table对象,判断该对象中的文本框个数
循环出表格中所有的TagName 判断类型是否是text 并且数量是否是20个,如果是 return false;大概思路这样