一个文本框A,一个文本框B,在A粘贴一串淘宝商品网址,网址中带有id=后面的大约10个左右连续的数字,提取那10个左右连续的数字到B文本框中,提取按钮上相应的代码如何加上去?我附上源代码
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>111111111</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<!--打开文本框中URL的JAVA -->
<script language="JavaScript" type="text/javascript">
function Open(){
  var url = document.getElementById("url").value;
  window.open (text.value+text1.value);
}
function clearContent(txt)
{
txt.value="";
}
</script>
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
</head>
<body onContextMenu="return false" >
<div align="center">
    <table width="900" border="0" cellspacing="8" background="images/login_border_img01.gif">
      <tr>
        <td height="147" valign="top"><table border="0" align="center" cellspacing="0" bgcolor="#FFFFFF">
          
          <tr>
            <td width="3592" height="66" colspan="2"><table width="900" border="0" align="center" cellspacing="0">
                <tr>
                  <td width="56" align="left">&nbsp;</td>
                  <td width="7" align="left" bgcolor="#88C4FF">&nbsp;</td>
                  <td width="552" bgcolor="#88C4FF"><input name="thisUrl" type="text" onclick="value=';focus()" id="thisUrl" height="8" style="height:25px; color:#666666; line-height:25px;" value="如:http://detail.tmall.com/item.htm?spm=a1z10.1.w7567245.5.uVg1oQ&id=17901080044" size="77"/></td>
                  <td width="42" align="left"><input type="submit" name="Submit" value="提取" /></td>
                  <td width="233" rowspan="3" align="right">&nbsp;</td>
                </tr>
                <tr>
                  <td height="36"></td>
                  <td colspan="2" align="left">点提取按钮,只提取上面网址<span class="STYLE1">ID=</span>后面的数字,然后附给下面的文本框中,<span class="STYLE1">ID=</span>的位置有时会不同</td>
                  <td></td>
                </tr>
                <tr>
                  <td align="left"><label></label></td>
                  <td bgcolor="#88C4FF"><input name="text" type="text" id="url" style="height:25px; color:#CCCCCC; background-color:#88C4FF; line-height:25px; visibility:hidden; " value="http://www.1111111.com/newtb/go.aspx?u=1S11411454&amp;Nid=" size="1" /></td>
                  <td bgcolor="#88C4FF"><input name="text1" type="text" id="text1"  height="8" style="height:25px; color:#666666; line-height:25px; " size="77" /></td>
                  <td align="left"><input name="button" type="button" onclick="Open()" value="打开"  /></td>
                </tr>
            </table></td>
          </tr>
          
          
        </table></td>
      </tr>
    </table>
    <label><br />
  </label>
    <label><br />
  </label>
</div>
</body>
</html>

解决方案 »

  1.   

    提取方面,我觉得最简单的办法可以这样:js的有个函数split(),你可以这样写:var getId = strObj.split('id=');这样,就能得到id后面的数字。
    然后设置文本框B的值:document.getElementById('Bid').value='getId';楼主可以参考
      

  2.   

    设置文本框B的值方面的代码我写错了,split返回的是数组,应该是这样:document.getElementById('Bid').value=getId[1]
      

  3.   

    document.getElementById('Bid').value=getId[1]