<a style="background-color:red">a</a>

解决方案 »

  1.   

    1.直接在该标签后面定义样式:
    <a style="background-color:red"></a>。
    2.用CSS中的类:.example
    {
     background-color:red;
    }
    <a class="example"></a>3.用CSS中元素直接定义样式方式:#example
    {
     background-color:red;
    }
    <a id="example"></a>
      

  2.   

    既然在js里提问 就用js来设定吧.首先找到这个<a>标签 如果有id则用document.getElementById来找 如果没有但知道DOM位置, getElementsByTagName[n]来找到此a结点 然后.style.backgroundColor="red";即可
    <html>
      <head>
        <title>change &lt;a&gt;'s backgound-color</title>
        <script type="text/javascript">
          function change1(){
    var _a = document.getElementById("test");
    _a.style.backgroundColor="red";
          }
          function change2(){
    var _a = document.getElementsByTagName("a")[1];//
    _a.style.backgroundColor="green";
          }
          /*以上两种方法通过不同方式找到了同一元素*/
          var num=1;
          function change(){
    if(num%2==0){
      change1();
    }else{
      change2();
    }
            num++;
          }
        </script>
      </head>
      <body>
        <a href="www.sina.com.cn">Let's go to SINA</a>
        <a id="test" href="www.baidu.com">Let's go to BAIDU</a>
        <button onclick="change()">change &lt;a&gt;'s color</button>
      </body>
    </html>