$() 方法是在DOM中的 document.getElementById() 方法的一个便利的简写。

解决方案 »

  1.   

    var $ = function (obj){return document.getElementById(obj);}
    以后document.getElementById("AC") 可以直接写为$("AC")
      

  2.   

    呵呵,上面那位不知道这样行不行?
    var aa = function (obj){return document.getElementById(obj);}
    以后document.getElementById("AC") 可以直接写为aa("AC")
      

  3.   

    你这样写是对的 任意字母都可以 呵呵 今天看了这里终于搞懂$做什么用了顺便总结下 呵呵 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>test</title>
    <style type="text/css">
    body{
    padding-left:3px;
    overflow:auto;
    background:transparent;
    margin-right:3px;
    background-repeat: no-repeat;
    }
    .d{
    border-style:solid;border-width:1px;border-color:orange;
      }
    </style>
    <script type="text/javascript">
    var $ = function (idValue){
    return document.getElementById(idValue); }
    var $F = function(idValue){
    return document.getElementById(idValue).value;
    }

    function showValue(){
    alert( $("txtInput").value);
    }
    </script>
    </head><body onclick="$("xiaoyizhi").style.display=none;">
    <div class="d" id="xiaoyizhi" style="width:400px;height:300px;">
    <input id="txtInput" type="text" class="d" onblur="showValue();">
    <input id="txtInput2" type="text" class="d" onblur="alert($F(this.id));;">
    </div>
    </body>
    </html>