| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5639 人关注过本帖
标题:js前台动态添加文本框,asp接收页面怎么获取文本框内容
只看楼主 加入收藏
gesongs
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:129
专家分:100
注 册:2011-7-7
结帖率:52.78%
收藏
已结贴  问题点数:0 回复次数:12 
js前台动态添加文本框,asp接收页面怎么获取文本框内容
前台代码:
<head>
<title>无标题文档</title>
</head>
<body>
<form name="form1" method="post" action="bb.asp">
  <div id="d">
    <input type="text" name="text_0"/>
    <input type="text1" name="text_02"/>
    <input type="text2" name="text_03"/>
  </div>
  <input name="button" type="button" id="b" value="添加"/>
  <label>
  <input type="submit" name="Submit" value="提交">
  </label>
</form>
</body>
<script language="javascript">
i = 1;
document.getElementById("b").onclick=function(){
  document.getElementById("d").innerHTML+='<div id="div_'+i+'">  <input name="text" name="text_'+i+'" type="text"  />  <input name="text1" name="text_'+i+'" type="text"  />  <input name="text2" name="text_'+i+'" type="text"  />  <input type="button" value="删除"  onclick="del('+i+')"/></div>';
  i = i + 1;
}
function del(o){
    document.getElementById("d").removeChild(document.getElementById("div_"+o));
}
</script>
asp接收页面怎么获取js里的“i”值?

[ 本帖最后由 gesongs 于 2011-9-26 18:23 编辑 ]
搜索更多相关主题的帖子: 前台 javascript function action button 
2011-09-26 16:43
xmlz
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:294
专家分:1392
注 册:2010-8-29
收藏
得分:2 
把i放在隐藏对象里传递过去:
document.getElementById("b").onclick=function(){
  document.getElementById("d").innerHTML+='<div id="div_'+i+'">  <input name="text" name="text_'+i+'" type="text"  />  <input name="text1" name="text_'+i+'" type="text"  />  <input name="text2" name="text_'+i+'" type="text"  /><input name="i" type="hidden" value='+i+' /><input type="button" value="删除"  onclick="del('+i+')"/></div>';
  i = i + 1;
}
2011-09-26 22:46
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:2 
<head>
<title>无标题文档</title>
<script language="javascript">
function form1_Submit()
{
  document.form1.action=self.location.href;
  document.form1.submit();
}
</script>
</head>
<body>
<%
   IF Request.Form("IsSubmit")="true" Then
      Dim i,Total
      Total=Request.Form("textInp").Count
      Response.Write "共"&Total&"个文本框"
      For i=0 To Request.Form("textInp").Count
          Response.Write "第"&i&"个文本框值为"&Request.Form("textInp")(i)&"<br/>"
      Next
   End IF
%>
<form name="form1" method="post" action="bb.asp">
  <div id="d">
    <input type="text" name="textInp"/>
    <input type="text" name="textInp"/>
    <input type="text" name="textInp"/>
  </div>
  <input name="button" type="button" id="b" value="添加"/>
  <label>
  <input type="button" name="Submit" onClick="form1_Submit();" value="提交">
  <input type="hidden" name="IsSubmit" value="true" />
  </label>
</form>
</body>
</html>

[ 本帖最后由 yms123 于 2011-9-27 12:32 编辑 ]
2011-09-27 12:30
gesongs
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:129
专家分:100
注 册:2011-7-7
收藏
得分:0 
谢谢版主!你的方法比较好用 但是新问题有来了

页面test1.asp :
 <td width="80%" bgcolor="#EEF7FD" class="category">
        <div id="d">
        名称:<input name="liao_hao" type="text" id="liao_hao" ondblclick="openwin()" value="双击选择料号"/>
        </div>
        <input name="button" type="button" id="b" value="添加"/>      
        <script language="javascript">
i = 1;
document.getElementById("b").onclick=function(){
  document.getElementById("d").innerHTML+='<div id="div_'+i+'">'+i+'料号:<input name="liao_hao'+i+'" type="text" ondblclick="openwin()" /><input type="button" value="删除"  onclick="del('+i+')"/></div>';
  i = i + 1;
}
function del(o){
    document.getElementById("d").removeChild(document.getElementById("div_"+o));
}
</script><script LANGUAGE="JavaScript">
function openwin() {
    window.open ("test.asp", "newwindow", "height=400, width=780, toolbar =no, menubar=no,top=180,left=190,  scrollbars=yes, resizable=no, location=no, status=no") //写成一行
   }
 </script>
          </td>
===========================================================================
菜单页面:test.asp
<table width="200" border="1">
  <tr onDblClick="ReturnValue()" >
<script language="javascript">
function ReturnValue()
{
window.opener.document.form1.liao_hao.value="123";//这里的liao_hao 如何获取test1.asp 里的liao_hao'+i+'值一一对应?
window.close();
}
</script>
    <td>123</td>
  </tr>
</table>


[ 本帖最后由 gesongs 于 2011-9-27 20:10 编辑 ]
2011-09-27 20:08
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
window.opener.document.form1.liao_hao.value="123";//这里的liao_hao 如何获取test1.asp 里的liao_hao'+i+'值一一对应?
你这里都设置了文本框照样可以获取值啊?把name属性都设置为:<input name="liao_hao"任何name属性一样的都可以自动变为数组,这个规律适用javascript和asp
<table width="200" border="1">
  <tr onDblClick="ReturnValue()" >
<script language="javascript">
function ReturnValue()
{
   var len=window.opener.document.form1.liao_hao.length;//js里取得数组大小用数组名.length
   for(var i=0;i<len;i++)
       window.opener.document.form1.liao_hao[i].value="123";//这里的liao_hao 如何获取test1.asp 里的liao_hao'+i+'值一一对应?
   window.close();
}
</script>
    <td>123</td>
  </tr>
</table>
2011-09-27 23:01
gesongs
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:129
专家分:100
注 册:2011-7-7
收藏
得分:0 
版主!这段代码 好像不行!
页面test1.asp :
<td width="80%" bgcolor="#EEF7FD" class="category">
        <div id="d">
        名称:<input name="liao_hao" type="text" id="liao_hao" ondblclick="openwin()" value="双击选择料号"/>
        </div>
        <input name="button" type="button" id="b" value="添加"/>      
        <script language="javascript">
i = 1;
document.getElementById("b").onclick=function(){
  document.getElementById("d").innerHTML+='<div id="div_'+i+'">'+i+'料号:<input name="liao_hao'+i+'" type="text" ondblclick="openwin()" /><input type="button" value="删除"  onclick="del('+i+')"/></div>';
  i = i + 1;
}
function del(o){
    document.getElementById("d").removeChild(document.getElementById("div_"+o));
}
</script><script LANGUAGE="JavaScript">
function openwin() {
    window.open ("test.asp", "newwindow", "height=400, width=780, toolbar =no, menubar=no,top=180,left=190,  scrollbars=yes, resizable=no, location=no, status=no") //写成一行
   }
</script>
 </td>

下述代码的值传送到 <input name="liao_hao'+i+'" type="text" ondblclick="openwin()" />里
的值都是一样的,希望是<input name=liao_hao1;<input name=liao_hao2;<input name=liao_hao3....各自获取各自的值!

菜单页面:test.asp

<table width="200" border="1">
  <tr onDblClick="ReturnValue()" >
<script language="javascript">
function ReturnValue()
{
   var len=window.opener.document.form1.liao_hao.length;//js里取得数组大小用数组名.length\  
 for(var i=0;i<len;i++)
       window.opener.document.form1.liao_hao[i].value="123";//这里的liao_hao 如何获取test1.asp 里的liao_hao'+i+'值一一对应?
   window.close();
}
</script>
    <td>123</td>
  </tr>
</table>


[ 本帖最后由 gesongs 于 2011-9-28 08:14 编辑 ]
2011-09-27 23:47
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:2 
到底是要什么效果?我没明白,似乎版主也没明白

是不是要这样的? --双击料号的文本框,弹出窗口选择一个料号,把选择的料号填入双击的那个文本框中。
 

----我怎能在别人的苦难面前转过脸去----
2011-09-28 09:47
gesongs
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:129
专家分:100
注 册:2011-7-7
收藏
得分:0 
是的!但是效果是 能添加多个 文本框  然后  选择的料号 能对应上 各自的文本框
图片附件: 游客没有浏览图片的权限,请 登录注册
2011-09-28 10:19
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
test1.asp
打开新窗口时URL加一个参数,用于指定文本框
补充一点,FF下添加一行时,input的值会还原(这里就是清空),是由于innerHTML引起的

 
程序代码:
 <div id="d">
        名称:<input name="liao_hao" type="text" id="liao_hao" ondblclick="openwin(this)" value="双击选择料号"/>
        </div>
        <input name="button" type="button" id="b" value="添加"/>      
        <script language="javascript">
i = 1;
document.getElementById("b").onclick=function(){
alert(document.getElementById("d").innerHTML)
  document.getElementById("d").innerHTML+='<div id="div_'+i+'">'+i+'料号:<input name="liao_hao" id="liao_hao'+i+'" type="text" ondblclick="openwin(this)" /><input type="button" value="删除"  onclick="del('+i+')"/></div>';
  i = i + 1;
}
function del(o){
    document.getElementById("d").removeChild(document.getElementById("div_"+o));
}
</script><script LANGUAGE="JavaScript">
function openwin(obj) {
    window.open ("test.asp?liaohao_id="+obj.id+"", "newwindow", "height=400, width=780, toolbar =no, menubar=no,top=180,left=190,  scrollbars=yes, resizable=no, location=no, status=no") //写成一行
   }
</script>

 

test.asp
程序代码:
<table width="200" border="1">
  <tr onDblClick="ReturnValue('0001')" >
    <td>0001</td>
  </tr>
  <tr onDblClick="ReturnValue('0002')" >
    <td>0002</td>
  </tr>
  <tr onDblClick="ReturnValue('0003')" >
    <td>0003</td>
  </tr>
</table>

<script language="javascript">
function ReturnValue(liaohao_value)
{
liaohao_id="<%=Request.QueryString("liaohao_id")%>";
window.opener.document.getElementById(liaohao_id).value=liaohao_value;
window.close();
}
</script>


[ 本帖最后由 dzt0001 于 2011-9-28 12:50 编辑 ]

----我怎能在别人的苦难面前转过脸去----
2011-09-28 12:47
gesongs
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:129
专家分:100
注 册:2011-7-7
收藏
得分:0 
dzt0001 谢谢你!搞定!
js的知识面太窄 openwin(this)  openwin(obj) 没搞懂 不知道彼此什么关系!
2011-09-28 14:05
快速回复:js前台动态添加文本框,asp接收页面怎么获取文本框内容
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015827 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved