日期:2014-05-16  浏览次数:20337 次

单选状态的问题
HTML code

<dl>
            <dt>New South Wales</dt>
                <dd><a href="javascript:void(0)" onclick="setcity('armidale',this)">Armidale</a><span></span></dd>    
                <dd><a href="javascript:void(0)" onclick="setcity('bathurst-orange',this)">Bathurst-Orange</a></dd>    
                <dd><a href="javascript:void(0)" onclick="setcity('brokenhill',this)">Broken Hill</a></dd>    
                <dd><a href="javascript:void(0)" onclick="setcity('centralcoastnsw',this)">Central Coast NSW</a></dd> 
                <dd><a href="javascript:void(0)" onclick="setcity('coffsharbour',this)">Coffs Harbour</a></dd>
                <dd><a href="javascript:void(0)" onclick="setcity('cooma',this)">Cooma</a></dd>    
                <dd><a href="javascript:void(0)" onclick="setcity('dubbo',this)">Dubbo</a></dd>
                <dd><a href="javascript:void(0)" onclick="setcity('goulburn',this)">Goulburn</a></dd>
                <dd><a href="javascript:void(0)" onclick="setcity('lismore',this)">Lismore</a></dd>    
                <dd><a href="javascript:void(0)" onclick="setcity('newcastle',this)">Newcastle</a></dd>        
                <dd><a href="javascript:void(0)" onclick="setcity('portmacquarie',this)">Port Macquarie</a></dd>     
                <dd><a href="javascript:void(0)" onclick="setcity('southcoastnsw',this)">South Coast NSW</a></dd>
                <dd><em><a href="javascript:void(0)" onclick="setcity('sydney',this)">Sydney</a></em></dd>
                <dd><a href="javascript:void(0)" onclick="setcity('tamworth',this)">Tamworth</a></dd>
                <dd><a href="javascript:void(0)" onclick="setcity('tweedheads',this)">Tweed Heads</a></dd>    
                <dd><a href="javascript:void(0)" onclick="setcity('waggawagga',this)">Wagga Wagga</a></dd>    
                <dd><a href="javascript:void(0)" onclick="setcity('wollongong',this)">Wollongong</a></dd>    
        </dl>



JScript code

function setcity(city,obj){
    obj.className="selected"; 
    var div=document.createElement('span');
    obj.appendChild(div);
    }



想实现单选,点击哪个,哪个就显示选中的状态,后面有一个勾(通过添加一个<span>),可是现在的问题是,点完一个,点下一个的时候,前面点的不会清除状态,导致越点的多,选中状态越多,帮帮忙吧~~



------解决方案--------------------
用jquery点击a的时候后面span写一个钩钩
$("dd").children("a").cilck(function(){
$("dd").children("span").remove();
$(this).next("span").html("√");

});