2012-03-22 2 views
1

하위 문자열을 사용하여 span 태그 내에 나타나는 ,을 제거하고 이름 만 표시하고 싶습니다. 다음은 작동해야하는 두 가지 사례입니다.자바 스크립트를 사용하는 하위 문자열 html 태그

Case1: <span class="datatableheader">No results found, </span> 
Case2: <span class="datatableheader">Jude Gomes, </span> 

하나의 함수는 두 경우 , 제거에 도움이 어떤 도움을 음미

<span class="datatableheader">No results found </span> 
<span class="datatableheader">Jude Gomes </span> 

같은 결과를 표시한다.

감사

+0

자신 @Kolink 더 잘 말했다 수 없습니다. 사람들이 다른 사람들의 노력에 감사를 표할 때 매우 짜증이납니다! 특히 –

답변

2
$(".datatableheader").html ($(".datatableheader").html().replace(",","")); 
0

이 또한

var parts = id.split(':'); //because u have case1: or case2: 
// it will split into string in array// 

$('#parts[1]').replace(",","")); 
//try to print that it will work 

좋은 질문을 시도 할 수 있습니다.

1

널리 .html가 콜백 함수를 받아들이는 인식 아니에요 :

$('.datatableheader').html(function(i,old) { 
    return old.replace(/, ?/g, ''); 
});​ 

http://jsfiddle.net/3fBY4/1/

+0

+1과 같이 많은 질문에 대답 할 수있는 시간을 찾을 수있는 사람은 선택자''.datatableheader ''가 하나 이상의 요소를 평가할 때 편리합니다. – Prusse

관련 문제