2 u011134641 u011134641 于 2015.07.27 21:03 提问

用jquer如何给 <li> 标签下的 所有的第二个和第三个<span>标签赋值

图片说明

4个回答

showbo
showbo   Ds   Rxr 2015.07.28 09:19
已采纳
 <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js"></script>
<ul id="ul">
    <li>
        <a href="javascript:void(0)">
            <span>卖5</span>
            <span class="" id="mcjg5">--</span>
            <span id="mcs15">--</span>
        </a>
    </li>
    <li>
        <a href="javascript:void(0)">
            <span>卖4</span>
            <span class="" id="mcjg4">--</span>
            <span id="mcs14">--</span>
        </a>
    </li>
</ul>
<script>
    $('#ul li span:not(:first-child)').html('new value');
</script>
guwei4037
guwei4037   Ds   Rxr 2015.07.27 21:21
 <html>
<head>
    <script src="http://code.jquery.com/jquery-1.6.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            var span1 = $("ul li a span[id*=mcjg]");
            $.each(span1,function(i,val){
                $("#"+val.id).html(i+"_"+ val.id);
            });

            var span2 = $("ul li a span[id*=mcs1]");
            $.each(span2,function(i,val){
                $(this).html(i+"_"+ val.id);
            });
        });
    </script>
</head>
<body>
    <ul>
        <li>
            <a href="javascript:void(0)">
                <span>卖5</span>
                <span class="" id="mcjg5">--</span>
                <span id="mcs15">--</span>
            </a>
        </li>
        <li>
            <a href="javascript:void(0)">
                <span>卖4</span>
                <span class="" id="mcjg4">--</span>
                <span id="mcs14">--</span>
            </a>
        </li>
    </ul>
</body>
</html>
beacon_2011
beacon_2011   Rxr 2015.07.28 08:57

$("#mcsl5").val("balabala")

yuke198907
yuke198907   2015.07.28 09:06

$("#mcsl5").html("balabala")

Csdn user default icon
上传中...
上传图片
插入图片