-->html
<body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</body-->css
body{
    border:1px #999 solid;
}-->jq
var array = [];
var id = 0;
$("div").map(function(){
    did[id++] = $(this).attr("id",tid);
});
$('#' + did[0].attr("id")).css("border-bottom","0");<--方法一
$("0").css("border-bottom","0");<--方法二两种方法都试过了,为什么不能把第一个div的下划线去掉?Jquery

解决方案 »

  1.   

    这里打错了,是 did[id++] = $(this).attr("id",id);
      

  2.   


    <!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=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <title>无标题文档</title>
    </head><body>
    <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <script type="text/javascript">
        var array = [];
    var id = 0;
    $("div").each(function(){
         array[id++] = $(this).attr("id",id);
    });
    alert(array.join());
    $(array[0]).css("border-bottom","1px solid #f00");
        </script>
    </body>
    </html>
      

  3.   

    这里打错了,是 did[id++] = $(this).attr("id",id);你是把元素填到了数组中,直接$(元素)却可
      

  4.   

    没有问题啊。<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <style type="text/css">
    div{
        border:1px #999 solid;
    width:200px;
    margin:20px;
    }
    </style><body>
        <div>111111111</div>
        <div>222222222</div>
        <div>333333333</div>
        <div>444444444</div>
        <div>555555555</div>
    </body>
    <script type="text/javascript">
    var array = [];
    var did=[];
    var id = 0;
    $("div").map(function(){
        did[id++] = $(this).attr("id",id);
    });
    $('#' + did[0].attr("id")).css("border-bottom","0");
    </script>
      

  5.   

    Quote: 引用 3 楼 xiaofanku 的回复:
    其实整段jq代码实在一个jq插件里的...(function ($) {
        $.fn.no = function(options){
            var defaults = {
                tab: ""
            }       
            var options = $.extend(defaults, options);
            var tabid = [];
            var tid = 0;
            var tab = $(this).find(options.tab);
            $(tab).map(function(){
             $(this).attr("id", tid);
             tabid[tid++] = $(this).attr("id");
            });
         $(tabid[0]").css("border-bottom","0");
        };    
    })(jQuery);--><!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=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <title>无标题文档</title>
    <script>
    $("#no").no({
    tab: ".tab"
    });
    </script>
    </head>
     
    <body>
    <div id="no">
        <div class="tab">1</div>
        <div class="tab">2</div>
        <div class="tab">3</div>
        <div class="tab">4</div>
        <div class="tab">5</div>
    </div>
    </body>
    </html>
      

  6.   

    常见的dom加载顺序问题,你代码运行时div还没创建。你的代码放到html的后面,或放到$(function(){//这里});//或放到onload事件里执行
      

  7.   

    Quote: 引用 7 楼 ftiger 的回复:
    放在底部了,还是无法进行操作,但是把代码改成$(".tab:first").css("border-bottom","0");
    就可以了,不是很明白js的机制.即使我改成$("#1").css("border-bottom","0");也是无法去掉底部的边框