<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
table{ width:100%;}
td{ background:#eee;}
</style>
<script>
window.onload=function(){
var a=document.getElementById("start").value;
var b=document.getElementById("finish").value;
         var c=document.getElementById("Submit");
c.submit()=chooseArea(x,y);
}
function chooseArea(x,y){
document.write("<table>");
for(i=x;i<=y;i++){
document.write("<tr>");
for(j=x;j<=i;j++){
document.write("<td>"+j+"*"+i+"</td>");
}
for(k=j;k<=y;k++){     
document.write("<td>"+"</td>");
}
document.write("</tr>");
}
document.write("</table>");
}
</script>
</head><body>
<script>
chooseArea(1,9)
</script>
<input type="text" id="start"/>--<input type="text" id="finish"/>
<input type="submit"  id="Submit" value="Submit"/>
</body>
</html>本来想点击按钮时显示从A到B的乘法表,现在却出问题了,去掉红色代码就显示正常,问题肯定在Submit事件上面。A:第一个输入框的值
B:第二个输入框的值

解决方案 »

  1.   

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <style>
    table{ width:100%;}
    td{ background:#eee;}
    </style>
    <script>
    window.onload=function(){ 
    var a=document.getElementById("start").value;
    var b=document.getElementById("finish").value;
      var c=document.getElementById("Submit");
    c.onclick=function(){chooseArea(1,9);}
    }
    function chooseArea(x,y){ 
    document.write("<table>"); 
    for(i=x;i<=y;i++){ 
    document.write("<tr>"); 
    for(j=x;j<=i;j++){ 
    document.write("<td>"+j+"*"+i+"</td>"); 

    for(k=j;k<=y;k++){   
    document.write("<td>"+"</td>"); 

    document.write("</tr>"); 

    document.write("</table>"); 
    }
    </script>
    </head><body><input type="text" id="start"/>--<input type="text" id="finish"/>
    <input type="submit" id="Submit" value="Submit"/>
    </body>
    </html>
      

  2.   

    c.submit()=chooseArea(x,y);
      c.onclick=chooseArea(x,y);//submit 函数是form标签才有的。
      

  3.   

    楼主是要这样的吗
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <style>
    table{ width:100%;}
    td{ background:#eee;}
    </style>
    <script>
    window.onload=function(){ 
      var c=document.getElementById("Submit");
    c.onclick=function(){
    var a=document.getElementById("start").value;
    var b=document.getElementById("finish").value;
    chooseArea(a,b);}
    }
    function chooseArea(x,y){ 
    if(x=="" || y=="" || isNaN(x) || isNaN(y))return;
    if(x>y){var z=x;x=y;y=z;}
    document.write("<table>"); 
    for(i=x;i<=y;i++){ 
    document.write("<tr>"); 
    for(j=x;j<=i;j++){ 
    document.write("<td>"+j+"*"+i+"</td>"); 

    for(k=j;k<=y;k++){   
    document.write("<td>"+"</td>"); 

    document.write("</tr>"); 

    document.write("</table>"); 
    }
    </script>
    </head><body><input type="text" id="start"/>--<input type="text" id="finish"/>
    <input type="submit" id="Submit" value="Submit"/>
    </body>
    </html>
      

  4.   

    我是想第一次的那个1-9的表格先显示,然后点击才显示输入框里面相对应的乘法表。
    1.可以做到,但是这样生成的话CSS失效了。是不是WINDOW.ONLOAD那里出了问题?
    2.用submit的话,是不是要在外面套个,<form id="f">,然后f.name.submit()这样吗?
      

  5.   

    c.submit()=chooseArea(x,y);
    应该是
    c.submit = chooseArea(x, y);
      

  6.   

    我再问个比较白痴的问题啊。
    window.onload=function(){ 
      var c=document.getElementById("Submit");
    c.onclick=function(){
    var a=document.getElementById("start").value;
    var b=document.getElementById("finish").value;
    chooseArea(a,b);}
    }a,b为什么一定要放在onclick函数里面呢?放在外面怎么会取不到呢?放在外面不是全局变量吗?
      

  7.   

    只是时序的问题
    因为有可能你的js运行的时候,dom还没有加载完全,所以取不到“start”“finish”元素,但如果放在了onload里,保证js运行的时候dom已经加载完全了