使用Javascript简单隐藏/扩展

use*_*419 1 javascript expand hide show-hide

我创建了一个简单的扩展/隐藏测试脚本:

<html>
<head>
<script type="type/javascript"><!--
function showHide(elementid){
    if (document.getElementById(elementid).style.display == 'none'){
        document.getElementById(elementid).style.display = '';
    } else {
        document.getElementById(elementid).style.display = 'none';
    }
}
//-->
</script>
</head>
<body>

<div><a href="javascript:showHide('div_1035677');">more...</a></div>

<div id="div_1035677" style="display:none">
HIDDEN CONTENT
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我得到一个我无法理解的错误消息(对象预期在第一行).我在上面的代码中没有看到任何错误.:-(

Art*_*kel 11

type="type/javascript"应该是type="text/javascript".


Luk*_*ins 5

更改type/javascripttext/javascript

完整示例:

<html>
<head>
  <script type="text/javascript" charset="utf-8">
  function showHide(elementid){
    if (document.getElementById(elementid).style.display == 'none'){
      document.getElementById(elementid).style.display = '';
    } else {
      document.getElementById(elementid).style.display = 'none';
    }
  }
  </script>
</head>
<body>
  <div><a href="javascript:showHide('div_1035677');">more...</a></div>
  <div id="div_1035677" style="display:none">
    HIDDEN CONTENT
  </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)