当前位置: 代码迷 >> JavaScript >> 单击链接后将不执行JavaScript代码
  详细解决方案

单击链接后将不执行JavaScript代码

热度:56   发布时间:2023-06-12 13:52:00.0

下面的代码应允许我单击文本链接,然后启动我的javascript函数。 但是,单击链接时没有任何反应。 我使用了本教程来帮助我

<html><body>
 <head>  
<script language="JavaScript" type="text/javascript">
            function getDSH(selectedField) 
            {
                document.Results.dshToPrint.value = selectedField;
                document.Results.getElementByID(selectedField).disabled = false;
                document.Results.submit();
            }
        </script>
    </head>
    <font size = '6' color = 'red'>Loop 1 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('1-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 2 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('2-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('2-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 3 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('3-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('3-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 4 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('4-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('4-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 5 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('5-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 6 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('6-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 7 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('7-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('7-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 8 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('8-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 9 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('9-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('9-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 10 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('10-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('10-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 11 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('11-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 12 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('12-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('12-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<p><a href = "javascript:getDSH('12-3');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 25GBase --allow-mix-speeds --ppm=2000000 </a></p> 
<font size = '6' color = 'red'>Loop 13 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('13-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
<p><a href = "javascript:getDSH('13-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
<p><a href = "javascript:getDSH('13-3');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 25GBase --allow-mix-speeds --ppm=2000000 </a></p> 
<form name = 'Results' method = 'post' action = '/cgi-bin/developer/dsh-generator-d.py'> 
<input type = 'hidden' name = '13-3' value = "[&quot;2015-07-03 14:46:00]" disabled> 
<input type = 'hidden' name = 'dshToPrint' > 
</form> 
</body></html>

这是语法错误吗?

编辑:当我单击一个链接时,会出现此错误:未捕获的TypeError:document.Results.getElementByID不是一个函数

首先,尝试从浏览器使用开发人员控制台(可能显示为“ Ctrl + Shift + I”)。

对于这个问题:Javascript区分大小写,因此您的“ getElementByID()”将不起作用; 使用“ getElementById()”代替。 另外,在调用document。[form] .getElementById()时,它将不起作用,您应该直接调用它:document.getElementById(id)。 不过,您的HTML中没有设置ID,因此点击将始终为函数中的此参数返回“空”。

我建议您首先尝试一些更简单的示例,然后再回到这个特定的示例!

将您的script标签移动到form的末尾。 JavaScript紧随HTML之后。

<html>
<body>
   <font size = '6' color = 'red'>Loop 1 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('1-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 2 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('2-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
   <p><a href = "javascript:getDSH('2-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 3 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('3-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
   <p><a href = "javascript:getDSH('3-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 4 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('4-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
   <p><a href = "javascript:getDSH('4-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 5 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('5-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 6 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('6-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 7 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('7-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
   <p><a href = "javascript:getDSH('7-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 8 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('8-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 9 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('9-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
   <p><a href = "javascript:getDSH('9-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 10 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('10-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
   <p><a href = "javascript:getDSH('10-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 11 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('11-1');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
   <font size = '6' color = 'red'>Loop 12 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('12-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
  <p><a href = "javascript:getDSH('12-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
  <p><a href = "javascript:getDSH('12-3');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 25GBase --allow-mix-speeds --ppm=2000000 </a></p> 
  <font size = '6' color = 'red'>Loop 13 --------------------------------------------------------------------------------</font><p><a href = "javascript:getDSH('13-1');"> ##! TEST FAIL: /switchCard/testVoltageMargining </a></p> 
  <p><a href = "javascript:getDSH('13-2');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 100GBase-4 --allow-mix-speeds --ppm=2000000 </a></p> 
  <p><a href = "javascript:getDSH('13-3');"> ##! TEST FAIL: /switchCard/testTraffic -l None -s 9208 -d 60 -r 25GBase --allow-mix-speeds --ppm=2000000 </a></p> 
  <form name = 'Results' method = 'post' action = '/cgi-bin/developer/dsh-generator-d.py'> 
  <input type = 'hidden' name = '13-3' value = "[&quot;2015-07-03 14:46:00]" disabled> 
  <input type = 'hidden' name = 'dshToPrint' > 
   </form>
<script language="JavaScript" type="text/javascript">
    function getDSH(selectedField) 
                {
                    document.Results.dshToPrint.value = selectedField;
                    document.Results.getElementByID(selectedField).disabled = false;
                    document.Results.submit();
                }
            </script>
    </body>
</html>
  相关解决方案