单击时未调用的功能?

时间:2017-01-18 19:15:24

标签: javascript

简单的Madblib项目。或者我想。这可能是一个简单的解决方案,但我非常感谢任何帮助,我似乎无法让它正常工作。

单击按钮时不调用该功能。有什么建议?我尝试过改变功能和形式的位置,以及调整""在输入字符串上。

<!DOCTYPE html>
    <html>
    <script>
    < head >
    script language = "JavaScript" >

    function Mission() {

        var a1 = document.AgentID.elements[0].value;
        var a2 = document.City.elements[0].value;
        var a3 = document.Country.elements[0].value;
        var a4 = document.Utensil.elements[0].value;
        var a5 = document.Adj1.elements[0].value;
        var a6 = document.Animal.elements[0].value;
        var a7 = document.Transportation.elements[0].value;

        document.write("<br>" + "<br>")
        document.write("Congradulations on accepting your next assignment Agent " + a1 + "")
        document.write("<br>" + "<br>")
        document.write("Your flight leaves to " + a2 + " , " + a3 + " in the next eight hours. You have been granted your weapon of choice, the " + a5 + " " + a4 + ". Your assignment is to capture the " + a6 + " with minimal casualties. Your extraction via " + a7 + " will be waiting.")
        document.write("<br>" + "<br>")
        document.write("Best of Luck Agent " + a1 + "")
        document.write("<br>")
        document.write("Operations HQ")
    }
    </script>

    </head>

    <body>
    <form id="AgentID" name="AgentID">
    AgentID <input type="text">
    </form>
    <form id="City" name="City">
    City <input type="text">
    </form>
    <form id="Country" name="Country">
    Country <input type="text">
    </form>
    <form id="Utensil" name="Utensil">
    Noun <input type="text">
    </form>
    <form id="Adj1" name="Adj1">
    Adjective <input type="text">
    </form>
    <form id="Animal" name="Animal">
    Animal <input type="text">
    </form>
    <form id="Transportaion" name="Transportaion">
    Transportation <input type="text">
    </form>
    <form>

    <input type="button" value="Accept" onClick="Mission()">

    </form>
    </body>
    </html>

1 个答案:

答案 0 :(得分:0)

您的代码中存在很多问题。

  1. HTML无效。标签不缺少结构。 Script需要位于headbody
  2. 您在JavaScript中使用Transportation的名称与在HTML中使用的名称相同。
  3. 以下应该工作。

    <!DOCTYPE html>
        <html>
    	<head>
      
        
        <script type="text/javascript">
    
        function Mission() {
    
            var a1 = document.AgentID.elements[0].value;
            var a2 = document.City.elements[0].value;
            var a3 = document.Country.elements[0].value;
            var a4 = document.Utensil.elements[0].value;
            var a5 = document.Adj1.elements[0].value;
            var a6 = document.Animal.elements[0].value;
            var a7 = document.Transportation.elements[0].value;
    
            document.write("<br>" + "<br>")
            document.write("Congradulations on accepting your next assignment Agent " + a1 + "")
            document.write("<br>" + "<br>")
            document.write("Your flight leaves to " + a2 + " , " + a3 + " in the next eight hours. You have been granted your weapon of choice, the " + a5 + " " + a4 + ". Your assignment is to capture the " + a6 + " with minimal casualties. Your extraction via " + a7 + " will be waiting.")
            document.write("<br>" + "<br>")
            document.write("Best of Luck Agent " + a1 + "")
            document.write("<br>")
            document.write("Operations HQ")
        }
        </script>
    
        </head>
    
        <body>
        <form id="AgentID" name="AgentID">
        AgentID <input type="text">
        </form>
        <form id="City" name="City">
        City <input type="text">
        </form>
        <form id="Country" name="Country">
        Country <input type="text">
        </form>
        <form id="Utensil" name="Utensil">
        Noun <input type="text">
        </form>
        <form id="Adj1" name="Adj1">
        Adjective <input type="text">
        </form>
        <form id="Animal" name="Animal">
        Animal <input type="text">
        </form>
        <form id="Transportation" name="Transportation">
        Transportation <input type="text">
        </form>
        <form>
    
        <input type="button" value="Accept" onClick="Mission()">
    
        </form>
        </body>
        </html>