jquery查找替换的问题

无爱大叔 2013-01-09 12:50:05
<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>
...全文
247 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞翔coder 2013-01-11
  • 打赏
  • 举报
回复
根据title是“星期几”,来改变span的innerText属性的值。 基础很重要!
mjhwy 2013-01-11
  • 打赏
  • 举报
回复
基础很重要啊
scscms太阳光 2013-01-09
  • 打赏
  • 举报
回复
<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>
fzfei2 2013-01-09
  • 打赏
  • 举报
回复
7楼的要改下

$('#t1 th span').each(function(i,v){
  v.innerHTML='日一二三四五六'.charAt(i)
});
fzfei2 2013-01-09
  • 打赏
  • 举报
回复
<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)
});
lyl911221 2013-01-09
  • 打赏
  • 举报
回复
qqqqqqqq_2013 2013-01-09
  • 打赏
  • 举报
回复
引用 楼主 xhbmj 的回复:
<th title="星期日" role="columnheader"><span>星</span></th> <th title="星期一" role="columnheader"><span>星</span></th> <th title="星期二" role="columnheader"><span>星</span></th> <th title="星期三" role="columnh……
lz这个其实只要更新<span>标签里的内容就可以了: <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>

$(document).ready(function() {
        $("th span").each(function(index, dom) {
            $(this).text($(this).parent().attr('title').substring(2, 3));
        });
    });

  • 打赏
  • 举报
回复

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/JavaScript">
	$(function(){
		$("#abv").click(function(){
			var ar=new Array();
			ar=["日","一","二","三","四","五","六"];
			for(var i=0;i<ar.length;i++){
				$("th").eq(i).empty().append(ar[i]);
			}
		});
	})
</script>

<input type="button" id="abv" value="测试用按钮"/>
<table border="1" cellpadding="15" >
<tr>
 <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>
</tr>	
</table>
fzfei2 2013-01-09
  • 打赏
  • 举报
回复
<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) 
      });
  • 打赏
  • 举报
回复
$(function() {
	$('th').find('span').each(function(index, dom) {
		$(this).html($(this).parent().attr('title').substring(2, 3));								   
	});
});

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧