某个点不允许使用Onclick属性

时间:2014-10-26 17:56:25

标签: javascript html

我正在开展一个学校项目,W3C HTML验证器告诉我"第19行,第59列:此时元素输入上不允许属性onlcick。"任何人都可以向我解释为什么会这样吗?我目前的代码是:



<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Multi Search Engines</title>
</head>

<body>
  <a href="../../index.htm" title="Index">Web Program Homepage</a>
  <br>
  <a href="../home.htm" title="Index">ITWP Course Homepage</a>
  <form action="searchForm" name="searchForm">
    <p>Search for
      <input type="text" name="searchTerm" />from
      <select name="engines">
        <option value="http://www.altavista.com/cgi-bin/query?kl=XX&amp;pgx=q&amp;Translate=on&amp;q=">Alta Vista</option>
        <option value="http://search.aol.com/dirsearch.adp?query=">AOL</option>
        <option value="http://www.google.com/search?q=">Google</option>
        <option value="http://search.lycos.com/default.asp?lpv=l&amp;loc=searchhp&amp;tab=web&amp;query=">Lycos</option>
        <option value="http://search.yahoo.com/search?p=" selected="selected">Yahoo!</option>
      </select>
      <input type="button" value="Search" onlcick="doSearch()" />
    </p>
  </form>
  <script type="text/javascript">
    /* <![CDATA[ */
    function doSearch() {
        var selectedItem = document.searchForm.engines.selectedIndex;
        if (selectedItem == -1)
          window.alert("You must select a search engine.");
        else
          location.href = document.searchForm.engines.options[selectedItem].value + document.searchForm.searchTerm.value;
      }
      /* ]]> */
  </script>
  <p>This web page allows a user to input a search query and choose which search engine to use to search for the information</p>
  <a href="http://validator.w3.org/check?uri=referer" title="HTML5 Validation">HTML5 Validation</a>
</body>

</html>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:3)

你有一个拼写错误:onlcick="doSearch()" />应该是:onclick

将行更改为:

<input type="button" value="Search" onclick="doSearch()" />

答案 1 :(得分:2)

输入“onclick”而不是“onclick”!?