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

jquery查找替换的问题
<th title="星期日" role="columnheader"><span>星</span></th>
<th title="星期一" role="columnheader"><span>星</span></th>
<th title="星期二" role="columnheader"><span>星</span></th>
<th title="星期三" role="columnheader"><span>星</span></th>
<th title="星期四" role="columnheader"><span>星</span></th>
<th title="星期五" role="columnheader"><span>星</span></th>
<th title="星期六" role="columnheader"><span>星</span></th>
如上html,如何用jquery将上面代码变成:
<th title="星期日" role="columnheader"><span>日</span></th>
<th title="星期一" role="columnheader"><span>一</span></th>
<th title="星期二" role="columnheader"><span>二</span></th>
<th title="星期三" role="columnheader"><span>三</span></th>
<th title="星期四" role="columnheader"><span>四</span></th>
<th title="星期五" role="columnheader"><span>五</span></th>
<th title="星期六" role="columnheader"><span>六</span></th>

------解决方案--------------------
<table>
<th title="星期日" role="columnheader"><span>星</span></th>
<th title="星期一" role="columnheader"><span>星</span></th>
<th title="星期二" role="columnheader"><span>星</span></th>
<th title="星期三" role="columnheader"><span>星</span></th>
<th title="星期四" role="columnheader"><span>星</span></th>
<th title="星期五" role="columnheader"><span>星</span></th>
<th title="星期六" role="columnheader"><span>星</span></th>
</table>
<script type="text/javascript">
    $("th[role='columnheader']").each(function(i,item){
        $(this).find("span").text($(this).attr("title").substring(2,3));
    })
</script>
------解决方案--------------------
$(function() {
$('th').find('span').each(function(index, dom) {
$(this).html($(this).parent().attr('title').substring(2, 3));    
});
});

------解决方案--------------------
<table id="t1">
<th title="星期日" role="columnheader"><span>星</span></th>
<th title="星期一" role="columnheader"><span>星</span></th>
<th title="星期二" role="columnheader"><span>星</span></th>
<th title="星期三" role="columnheader"><span>星</span></th>
<th title="星期四" role="columnheader"><span>星</span></th>
<th title="星期五" role="columnheader"><span>星</span></th>
<th title="星期六" role="columnheader"><span>星</span></th>
</table>
 加上ID效率高点,多个的就用1,2L的方法

     $('#t1 th span').each(function(i,v){
        v.innerHTML=v.parentNode.title.slice(-1) 
      });

------解决方案-----------------