首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jquery查找替换的有关问题

2013-01-21 
jquery查找替换的问题th title星期日 rolecolumnheaderspan星/span/thth title星期一 r

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) 
      });

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



[解决办法]
<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>


再简化一下


$('#t1 th span').each(function(i,v){
  v.innerHTML='日,一,二,三,四,五,六'.charAt(i)
});

[解决办法]
7楼的要改下

$('#t1 th span').each(function(i,v){
  v.innerHTML='日一二三四五六'.charAt(i)
});

[解决办法]
基础很重要啊
[解决办法]
根据title是“星期几”,来改变span的innerText属性的值。

基础很重要!

热点排行