注:函数名是动态生成的,真实的函数如下
function qm_enableTab_6404(obj, scale, label)
{    
  for (i = 1; i <= 9; i++)    
  {      
    document.getElementById('qm_ch_tab' + i + '_6404').className =      (i == obj) ? 'qmmt_tabactive' : 'qmmt_tab';      document.getElementById('qm_ch_tab' + i + '_6404').style.cursor =      (i == obj) ? 'default' : (qm_isIE_6404()) ? 'hand': 'pointer';      document.getElementById('qm_ch_tab' + i + '_6404').style.borderTopWidth =      (i == obj) ? '0px' : '1px';    
  }    
  var chtype = document.charttypes.chtype[0].value;    
  for (var i = 0; i < document.charttypes.chtype.length; i++)    
  {      
     if (document.charttypes.chtype[i].checked)      
 {        
    chtype = document.charttypes.chtype[i].value;      
 }    
  }    
  if (chtype != 'Java') 
  {      
 document.getElementById('dgraph_6404').src = 'http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL&chscale=' 
   + scale + '&chtype=' + chtype + 
   '&chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf';  
  }    
  document.getElementById('qm_label').innerHTML = label;  
}  
需要修改其中的charttypes为form[0]

解决方案 »

  1.   

    function qm_enableTab_6404(obj, scale, label,tform) 
    {     var myform = eval("document."+tform);
      for (i = 1; i  <= 9; i++)     
      {       
        document.getElementById('qm_ch_tab' + i + '_6404').className =      (i == obj) ? 'qmmt_tabactive' : 'qmmt_tab';      document.getElementById('qm_ch_tab' + i + '_6404').style.cursor =      (i == obj) ? 'default' : (qm_isIE_6404()) ? 'hand': 'pointer';      document.getElementById('qm_ch_tab' + i + '_6404').style.borderTopWidth =      (i == obj) ? '0px' : '1px';     
      }     
      var chtype = myform.chtype[0].value;     
      for (var i = 0; i  < myform.chtype.length; i++)     
      {       
         if (myform.chtype[i].checked)       
     {         
        chtype = myform.chtype[i].value;       
     }     
      }     
      if (chtype != 'Java')  
      {       
     document.getElementById('dgraph_6404').src = 'http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL&chscale='  
       + scale + '&chtype=' + chtype +  
       '&chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf';   
      }     
      document.getElementById('qm_label').innerHTML = label;   
    }   
    参考一下.
    呵呵,你1楼的说法都有点看不懂,不过二楼这个用上面的倒是可以实现,你试试行不行,就是要多加一个fomr名字的参数
      

  2.   

    最真实的代码如下,这是第三方提供的数据源,其中的script源打印一堆html超文本,对方不肯改生成的脚本,所以只好用javascript动态修改里面的东西:注里面的js会产生form,这就造成了以下类似的问题
    <form name=f1 id=f1>
      <form name=f2 id=f1>
         <script language=javascript>
            function btnOnclick(){
              alert(1);
              document.f2.submit();
            }
         </script>
         <input type=button value="testing" onclick="btnOnclick()">
      </form>
    </form>点击testing按钮无效报错
    <from name=f1 id=f1>
    <div id="qmBasicChart">
    <link rel="stylesheet" href="http://app.quotemedia.com/css/tools.css" />
    <script type="text/javascript" src="http://test.kkkk.com/quotetools/charts.go?k=1"></script>
    <div style="text-align: right; width: 812px; padding: 12px 0px 0px 0px;">
    <a href="Charts.aspx?showAdvancedCharts=1" class="qmmt">Interactive and Comparative Charts</a>
    </div>
    </div>
    <form>
      

  3.   

    测试了一下在ie下form不能嵌套,但在ff下可以.
    <body>
    <form id=f1 name=f1> 
       <form id="f2" name="f2"> 
          <script language=javascript> 
            function btnOnclick(){ 
              alert(1); 
              document.getElementById("f2").submit(); 
            } 
          </script> 
          <input type=button value="testing" onclick="btnOnclick()"> 
       </form> 
    </form> 
    </body>
    form不要嵌套而用其他办法解决.
      

  4.   

    to myvicy :谢谢,偶刚想到其它办法了,form的嵌套是没办法,但javascript有一个特性,就是存在两个同名函数的情况下,执行后一个,修改后的代码类似如下<link rel="stylesheet" href="http://app.quotemedia.com/css/tools.css" /><body >
    <form name="aspform">
    <META HTTP-EQUIV="imagetoolbar" CONTENT="no"><script type="text/javascript">  
    function qm_isIE_6404() 
    {    
      var ua = navigator.userAgent.toLowerCase();
      var isIE = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) );    
      return (isIE);  
    }  function qm_enableTab_6404(obj, scale, label)
    {    
      for (i = 1; i <= 9; i++)    
      {      
        document.getElementById('qm_ch_tab' + i + '_6404').className =      (i == obj) ? 'qmmt_tabactive' : 'qmmt_tab';      document.getElementById('qm_ch_tab' + i + '_6404').style.cursor =      (i == obj) ? 'default' : (qm_isIE_6404()) ? 'hand': 'pointer';      document.getElementById('qm_ch_tab' + i + '_6404').style.borderTopWidth =      (i == obj) ? '0px' : '1px';    
      }    
      var chtype = document.charttypes.chtype[0].value;    
      for (var i = 0; i < document.charttypes.chtype.length; i++)    
      {      
         if (document.charttypes.chtype[i].checked)      
     {        
        chtype = document.charttypes.chtype[i].value;      
     }    
      }    
      if (chtype != 'Java') 
      {      
     document.getElementById('dgraph_6404').src = 'http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL&chscale=' 
       + scale + '&chtype=' + chtype + 
       '&chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf';  
      }    
      document.getElementById('qm_label').innerHTML = label;  
    }  function qm_enableJava_6404()  
    {    
       if (document.getElementById('qm_label').innerHTML.substring(0, 4) != 'Java') 
       {      
          document.location.href =      
      'http://app.quotemedia.com/quotetools/clientForward?targetURL=http%3A%2F%2Fdev.zecco.com%2Fquotes%2Fbeta%2Fcharts.aspx%3FSymbol%3DAAPL&targetsym=&targettype=null&targetex=&qmpage=true&action=showCharts&symbol=AAPL&chtype=Java';    
       }  
    }  function qm_enableSrc_6404(chtype)  
    {    
      if (document.getElementById('qm_label').innerHTML.substring(0, 4) == 'Java') 
      {      
         document.location.href =      'http://app.quotemedia.com/quotetools/clientForward?targetURL=http%3A%2F%2Fdev.zecco.com%2Fquotes%2Fbeta%2Fcharts.aspx%3FSymbol%3DAAPL&targetsym=&targettype=null&targetex=&qmpage=true&action=showCharts&symbol=AAPL&chtype=' +      chtype;    
      } else 
      {      
         var oldSrc = document.getElementById('dgraph_6404').src;      
     var chIndex = oldSrc.indexOf("chtype=") + 7;      
     var part2 = oldSrc.substring(chIndex, oldSrc.length);      
     var newSrc = oldSrc.substring(0, chIndex) + chtype + part2.substring(part2.indexOf("&"), part2.length);      
     document.getElementById('dgraph_6404').src = newSrc;    
      }  
    }  function openHelp_6404() 
    {    
       var w = 520;    
       var h = 520;    
       var winl = (screen.width - w) / 2;    
       var wint = (screen.height - h) / 2;    
       var winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl +                   ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';    win =    
       window.open("http://app.quotemedia.com/quotetools/javaChartHelp.go", "JavaChartHelp", winprops);    
       if (parseInt(navigator.appVersion) >= 4) 
       {      
          win.focus();    
       }  
    }</script>
      

  5.   

    <table cellpadding="0" cellspacing="0" border="0" class="qmmt_main" width="812">
      <tr>  
        <td style="text-align: center">    
      <div class="qmmt_header_bar" style="padding-top: 1px; padding-bottom: 1px; border-bottom-width: 1px;">      
        <table cellpadding="0" cellspacing="0" border="0" width="100%">        
      <tr>          
        <td><span class="qmmt_header_text" style="padding-left: 3px">Charts for Apple Inc. (AAPL)</span></td>          
    <td class="qmmt_header_text" style="text-align: right; padding-right: 6px; font-weight:normal;">            
      <div id="qm_textChange_0833"><span class="qmmt_header_text" style="font-weight:normal;">Mar 11 6:40 AM EDT</span></div>
      <script type="text/javascript">
        function qm_UpdateText_0833(phase)
    {    
       switch (phase)    
       {        
          case 1: 
        document.getElementById('qm_textChange_0833').innerHTML = '<span class="qmmt_header_text" style="font-weight:normal;">delayed 20 minutes</span>'; 
    setTimeout("qm_UpdateText_0833(2)", 5000); 
    break;        
      case 2: 
        document.getElementById('qm_textChange_0833').innerHTML = '<span class="qmmt_header_text" style="font-weight:normal;">Mar 11 6:40 AM EDT</span>'; 
    setTimeout("qm_UpdateText_0833(3)", 5000); 
    break;        
      case 3: 
        document.getElementById('qm_textChange_0833').innerHTML = '<a href="http://www.quotemedia.com/" target="_top" style="text-decoration:none;"><span class="qmmt_header_text" style="font-weight:normal;">&copy; quotemedia.com</span></a>'; 
    setTimeout("qm_UpdateText_0833(1)", 5000); 
    break;    
    }
    }
    qm_UpdateText_0833(2);
      </script>           
    </td>
      </tr>      
    </table>    
      </div>  
    </td>
      </tr>
      <tr>  <!-- main content -->  
        <td>    
      <div class="qmmt_cycle" style="padding-top: 1px; padding-bottom: 5px; border-bottom-width: 1px;">      
        <table cellpadding="0" cellspacing="0" border="0" width="100%">        
      <tr>          
        <form name="charttypes">            
      <td class="qmmt_text" valign="bottom" width="20%" id="qm_label" style="padding-left: 6px; font-weight: bold;" align="left">Intraday</td>  
      <td width="80%" style='padding-right: 6px;' align="right">              
        <table cellpadding="0" cellspacing="0" align="right">
      <tr>
        <td class="qmmt_text" style="font-weight: normal;" valign="bottom" align="right">
      <INPUT type="radio" class="qm_radio_input" name="chtype" value="FinancialAreaChart"
        onClick="qm_enableSrc_6404('FinancialAreaChart')">                  
    </td>
    <td class="qmmt_header_text" valign="bottom" style="font-weight: normal;" align="left">Area&nbsp;</td>
    <td class="qmmt_text" style="font-weight: normal;" valign="bottom" align="right">
      <INPUT type="radio" class="qm_radio_input" name="chtype" value="FinancialLine" checked="true" 
        onClick="qm_enableSrc_6404('FinancialLine')">                
    </td>
    <td class="qmmt_header_text" valign="bottom" style="font-weight: normal;" align="left">Line&nbsp;</td>  
    <td class="qmmt_text" style="font-weight: normal;" valign="bottom" align="right">
      <INPUT type="radio" class="qm_radio_input" name="chtype" value="FinancialBar" onClick="qm_enableSrc_6404('FinancialBar')">
    </td>
    <td class="qmmt_header_text" valign="bottom" style="font-weight: normal;" align="left">Bar&nbsp;</td>
    <td class="qmmt_text" style="font-weight: normal;" valign="bottom" align="right">
      <INPUT type="radio" class="qm_radio_input" name="chtype" value="FinancialCandleStick" 
        onClick="qm_enableSrc_6404('FinancialCandleStick')">                
    </td>
    <td class="qmmt_header_text" valign="bottom" style="font-weight: normal;" align="left">Candlestick</td>
      </tr>
    </table>            
      </td>                      
        </form>        
      </tr>
    </table>    
      </div>
    </td>
      </tr>
      <tr>
        <td id="chart_cell_6404" align="center">    
      <img id="dgraph_6404" width="812" height="350"       
        src="http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL&chscale=1d&chtype=FinancialLine&chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf"       GALLERYIMG="no">  
      <table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
        <tr>    
      <td id="qm_ch_tab1_6404" class="qmmt_tabactive" onclick="qm_enableTab_6404('1', '1d', 'Intraday')" 
        style="cursor: default; border-left: 0px none; border-bottom: 0px none; border-right: 0px none; border-top-width: 0px; padding-top:1px; padding-bottom:1px;">Intraday</td>    
      <td id="qm_ch_tab2_6404" class="qmmt_tab" onclick="qm_enableTab_6404('2', '5d', '1 Week')" 
        style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;">5 Dy</td>    
      <td id="qm_ch_tab3_6404" class="qmmt_tab" onclick="qm_enableTab_6404('3', '1m', '1 Month')" 
    style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;">1 Mo</td>    
      <td id="qm_ch_tab4_6404" class="qmmt_tab" onclick="qm_enableTab_6404('4', '3m', '3 Month')" 
        style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;">3 Mo</td>
      <td id="qm_ch_tab5_6404" class="qmmt_tab" onclick="qm_enableTab_6404('5', '6m', '6 Month')" 
        style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;">6 Mo</td>    
      <td id="qm_ch_tab6_6404" class="qmmt_tab" onclick="qm_enableTab_6404('6', '1y', '1 Year')"        
        style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;">1 Yr</td>    
      <td id="qm_ch_tab7_6404" class="qmmt_tab" onclick="qm_enableTab_6404('7', '2y', '2 Year')" 
        style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;">2 Yr</td>    
      <td id="qm_ch_tab8_6404" class="qmmt_tab" onclick="qm_enableTab_6404('8', '5y', '5 Year')"   
        style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;"">5 Yr</td>    
      <td id="qm_ch_tab9_6404" class="qmmt_tab" onclick="qm_enableTab_6404('9', '10y', '10 Year')"       
        style="cursor: default; border-right: 0px; border-bottom: 0px; padding-top:1px; padding-bottom:1px;"">10 Yr</td>  
    </tr>
      </table>  
    </td>
      </tr>
    </table>
    </form>
    </body>
      

  6.   

    以下是偶刚写的追加代码
    <script language=javascript>
      var theObj = document.getElementsByTagName("img");
      var randomNum=0;
      for (var i = 0;i < theObj.length ;i++ )
      {
        if (theObj[i].id.substring(0,6) == "dgraph")
        {
      randomNum = theObj[i].id.substring(7,theObj[i].id.length);
      break;
        }
      }  var basicFirstUrl = document.getElementById("dgraph_"+randomNum).src;
      var basicEndUrl = "";
      var arr;
      //-- remove the chscale and chtype parameters 
      arr = basicFirstUrl.split('&chscale=');
      basicFirstUrl= arr[0] + arr[1].substring(arr[1].indexOf('&'));  arr = basicFirstUrl.split('&chtype=');
      basicFirstUrl= arr[0] + arr[1].substring(arr[1].indexOf('&'));
      //--  basicFirstUrl : http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL
      //--  basicEndUrl : &chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf
      arr = basicFirstUrl.split('&symbol=');
      basicFirstUrl=arr[0]+"&symbol="+arr[1].substring(0,arr[1].indexOf('&'));
      basicEndUrl = arr[1].substring(arr[1].indexOf('&'),arr[1].length);  document.write(" <script language=javascript>");
      document.write(" function qm_enableTab_"+randomNum+"(obj, scale, label)");
      document.write(" {");
      document.write("   for (i = 1; i <= 9; i++)");
      document.write("   {      ");
      document.write("     document.getElementById('qm_ch_tab'+i+'_"+randomNum+"').className=(i==obj)?'qmmt_tabactive':'qmmt_tab';");
      document.write("     document.getElementById('qm_ch_tab'+i+'_"+randomNum+"').style.cursor=(i == obj)?'default':'pointer';");
      document.write("     document.getElementById('qm_ch_tab'+i+'_"+randomNum+"').style.borderTopWidth=(i==obj)?'0px':'1px';    ");
      document.write("   }    ");
      document.write("   var chtype=document.forms[0].chtype[0].value;");
      document.write("   for (var i=0; i<document.forms[0].chtype.length; i++) ");
      document.write("   {      ");
      document.write("      if (document.forms[0].chtype[i].checked)");
      document.write("      {        ");
      document.write("         chtype = document.forms[0].chtype[i].value;");
      document.write("      }    ");
      document.write("   }    ");
      document.write("   if (chtype != 'Java') ");
      document.write("   {      ");
      document.write("      document.getElementById('dgraph_"+randomNum+"').src = '"+basicFirstUrl+"&chscale='+scale+'&chtype='+chtype+'"+basicEndUrl+"'; ");
      document.write("   }    ");
      document.write("   document.getElementById('qm_label').innerHTML = label;  ");
      document.write(" }  ");
      document.write("<\/script>");
    </script>
      

  7.   

    注:<form name="aspform">    ............  </form>中的代码是通过.js生成的,谢谢myvicy !
      

  8.   

    你是想修改函数的执行代码还是想嵌套form?
    修改函数代码比较容易,但是貌似form嵌套现在的浏览器中还存在大量问题.
      

  9.   

    原来是想修改函数代码,把以下函数中的charttypes改为form[0],有办法吗?
    function qm_enableTab_6404(obj, scale, label) 
    {     
      for (i = 1; i  <= 9; i++)     
      {       
        document.getElementById('qm_ch_tab' + i + '_6404').className =      (i == obj) ? 'qmmt_tabactive' : 'qmmt_tab';      document.getElementById('qm_ch_tab' + i + '_6404').style.cursor =      (i == obj) ? 'default' : (qm_isIE_6404()) ? 'hand': 'pointer';      document.getElementById('qm_ch_tab' + i + '_6404').style.borderTopWidth =      (i == obj) ? '0px' : '1px';     
      }     
      var chtype = document.charttypes.chtype[0].value;     
      for (var i = 0; i  < document.charttypes.chtype.length; i++)     
      {       
         if (document.charttypes.chtype[i].checked)       
     {         
        chtype = document.charttypes.chtype[i].value;       
     }     
      }     
      if (chtype != 'Java')  
      {       
     document.getElementById('dgraph_6404').src = 'http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL&chscale='  
       + scale + '&chtype=' + chtype +  
       '&chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf';   
      }     
      document.getElementById('qm_label').innerHTML = label;   
    }   
      

  10.   

    多加一个参数
    调用的时候
    qm_enableTab_6404(obj, scale, label,"form[0]")  function qm_enableTab_6404(obj, scale, label,tform)  
    {     var myform = eval("document."+tform); 
      for (i = 1; i   <= 9; i++)      
      {        
        document.getElementById('qm_ch_tab' + i + '_6404').className =      (i == obj) ? 'qmmt_tabactive' : 'qmmt_tab';      document.getElementById('qm_ch_tab' + i + '_6404').style.cursor =      (i == obj) ? 'default' : (qm_isIE_6404()) ? 'hand': 'pointer';      document.getElementById('qm_ch_tab' + i + '_6404').style.borderTopWidth =      (i == obj) ? '0px' : '1px';      
      }      
      var chtype = myform.chtype[0].value;      
      for (var i = 0; i   < myform.chtype.length; i++)      
      {        
         if (myform.chtype[i].checked)        
     {          
        chtype = myform.chtype[i].value;        
     }      
      }      
      if (chtype != 'Java')   
      {        
     document.getElementById('dgraph_6404').src = 'http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL&chscale='   
       + scale + '&chtype=' + chtype +   
       '&chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf';    
      }      
      document.getElementById('qm_label').innerHTML = label;    
    }  
      

  11.   

    或者直接改函数代码:
      <script language=javascript> 
    /*例*/
            function btnOnclick(){ 
              //alert(1); 
      return true;
    //          document.getElementById("f2".submit(); 
            } 
    eval(btnOnclick.toString().replace("true","false"));
    alert(btnOnclick())
    /*例*/
    /*以下自己根据实际改*/
            function qm_enableTab_6404(obj, scale, label)  
    {      
      for (i = 1; i   <= 9; i++)      
      {        
        document.getElementById('qm_ch_tab' + i + '_6404').className =      (i == obj) ? 'qmmt_tabactive' : 'qmmt_tab';      document.getElementById('qm_ch_tab' + i + '_6404').style.cursor =      (i == obj) ? 'default' : (qm_isIE_6404()) ? 'hand': 'pointer';      document.getElementById('qm_ch_tab' + i + '_6404').style.borderTopWidth =      (i == obj) ? '0px' : '1px';      
      }      
      var chtype = document.charttypes.chtype[0].value;      
      for (var i = 0; i   < document.charttypes.chtype.length; i++)      
      {        
         if (document.charttypes.chtype[i].checked)        
     {          
        chtype = document.charttypes.chtype[i].value;        
     }      
      }      
      if (chtype != 'Java')   
      {        
     document.getElementById('dgraph_6404').src = 'http://app.quotemedia.com/quotetools/getChart?webmasterId=93383&symbol=AAPL&chscale='   
       + scale + '&chtype=' + chtype +   
       '&chwid=812&chhig=350&chfill=eebb2962&chfill2=bb2962&chln=333333&chpccol=b54164&chfnts=8&chfrmon=false&chton=false&chpcon=true&chfnt=arial.ttf';    
      }      
      document.getElementById('qm_label').innerHTML = label;    
    }     eval(qm_enableTab_6404.toString().replace(/charttypes/ig,"form[0]"));

    alert(qm_enableTab_6404)
          </script> 
      

  12.   

    执行动态函数 可以试试  eval
      

  13.   

    to myvicy: 这正是我想要的,多谢啦!
      

  14.   

      谢谢您的回复,但您没有完全明白我的问题,我所处的是一个大的框架cs中,默认状态下就有一个form,我只能在这个form 内做事情,而目前引入了第三方接口又产生了一个form!