Java脚本警报无效

时间:2015-11-13 15:34:59

标签: javascript html

我正在学习JavaScript和HTML,并创建了一个网页,我在其中添加了一个按钮,点击该按钮可以提醒一些单词。但它没有发出警报。请帮忙。这是我的代码:

<html>
<head>
<title>
Pi^LaSa^
</title>
<script type="text/javascript" >
<!--
function developers(){
alert("The NaT Language was developed by Naman Chhaparia and Tanay Shankar,while sitting on the last bench of their former class 7 C while watching a boring dance practice !!
Naman and Tanay are best friends, and currently study at St. Thomas School, Ranchi,one of the best schools of the whole of Eastern-India. ")
}
//-->
</script>
</head>
<body>
<h1><span style="font-size:28px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#FF0000;"><span style="font-size: 36px;"><strong>Pi<sup>^</sup></strong></span></span><span style="color:#40E0D0;"><span style="font-size: 36px;"><strong>La</strong></span></span><span style="color:#00FF00;"><span style="font-size: 36px;"><strong>Sa<sup>^</sup></strong></span></span></span></h1>

<h2><span style="font-size:28px;"><span style="color:#00FF00;"><span style="font-size: 36px;"><strong><sup>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </sup></strong></span></span><span style="font-family:comic sans ms,cursive;"><span style="font-size: 36px;"><strong><sup><span style="font-size: 14px;">( The official website of the NaT Language )</span></sup></strong></span></span></span></h2>

<p><span style="font-size:28px;"><span style="font-family:comic sans ms,cursive;"><span style="font-size: 36px;"><span style="font-size: 14px;"><span style="font-family:arial,helvetica,sans-serif;">Hello, guys !! Welcome to the official website of the NaT ( Pi<sup>^</sup>LaSa<sup>^</sup> ) language, which was developed by Naman Chhaparia (</span></span></span></span></span>Pi<sup>^</sup>LaPaLaPi&nbsp; Mi<sup>^</sup>NoNoLaTesLaMaLoLa) , and Tanay Shankar (Sa<sup>^</sup>LaPiLa Ax Ni<sup>^</sup>NoLaPiPoLaMa ).</p>

<p>&nbsp;</p>

<input type="button" onclick="developers();" value="Learn about the Developers.">
</body>
</html>

2 个答案:

答案 0 :(得分:2)

如果您不确定如何使用长字符串,请不要开始使用长字符串编写简单脚本。从小处着手,继续建立。

像这样:https://jsfiddle.net/9mhtdssk/1/

保持简单。您修改后的以下代码版本:

<html>
<body>

<input type="button" onclick="developers();" value="Learn about the Developers.">
<script type="text/javascript">
  function developers() {
    alert('Simple small string of text');
  }
</script>

</body>
</html>

答案 1 :(得分:0)

检查它。你已经提醒了额外的空间。它工作。

&#13;
&#13;
<html>
    <head>
        <title>
            Pi^LaSa^
        </title>
        <script type="text/javascript" >

            function developers() {
                alert("The NaT Language was developed by Naman Chhaparia and Tanay Shankar,while sitting on the last bench of their former class 7 C while watching a boring dance practice !! Naman and Tanay are best friends,and currently study at St. Thomas School, Ranchi,one of the best schools of the whole of Eastern-India.");

            }

        </script>
    </head>
    <body>
        <h1><span style="font-size:28px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#FF0000;"><span style="font-size: 36px;"><strong>Pi<sup>^</sup></strong></span></span><span style="color:#40E0D0;"><span style="font-size: 36px;"><strong>La</strong></span></span><span style="color:#00FF00;"><span style="font-size: 36px;"><strong>Sa<sup>^</sup></strong></span></span></span></h1>

        <h2><span style="font-size:28px;"><span style="color:#00FF00;"><span style="font-size: 36px;"><strong><sup>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </sup></strong></span></span><span style="font-family:comic sans ms,cursive;"><span style="font-size: 36px;"><strong><sup><span style="font-size: 14px;">( The official website of the NaT Language )</span></sup></strong></span></span></span></h2>

        <p><span style="font-size:28px;"><span style="font-family:comic sans ms,cursive;"><span style="font-size: 36px;"><span style="font-size: 14px;"><span style="font-family:arial,helvetica,sans-serif;">Hello, guys !! Welcome to the official website of the NaT ( Pi<sup>^</sup>LaSa<sup>^</sup> ) language, which was developed by Naman Chhaparia (</span></span></span></span></span>Pi<sup>^</sup>LaPaLaPi&nbsp; Mi<sup>^</sup>NoNoLaTesLaMaLoLa) , and Tanay Shankar (Sa<sup>^</sup>LaPiLa Ax Ni<sup>^</sup>NoLaPiPoLaMa ).</p>

        <p>&nbsp;</p>

        <input type="button" onclick="developers();" value="Learn about the Developers.">
    </body>
</html>
&#13;
&#13;
&#13;