2013-05-05 41 views
0

我想轉換此:刪除由子和的indexOf標籤和它的內容在JavaScript

<html> 
s 
<RB:Block_Left>sss</RB:Block_Left> 
s 
hello 
</html> 

此,

<html> 
s 
s 
hello 
</html> 

這個代碼必須是喜歡我的文字區域做它,但不能工作!

<textarea id ="code"> 
<html> 
s 
<RB:Block_Left>sss</RB:Block_Left> 
s 
hello 
</html> 
</textarea> 
<br /> 
<input type="button" value="makeit!" onclick="ARAS()" /> 
<br /> 
<textarea id ="newcode"> 
</textarea> 
<script> 
function ARAS(){ 
    str=document.getElementById('code').value; 
    str=str.substring( + str.indexOf('<html>') - str.indexOf('<\/RB:Block_Left>') + str.indexOf('<\/RB:Block_Left>')); 
    document.getElementById('newcode').value=str; 
} 
</script> 

回答

0

更改行:

str=str.substring( + str.indexOf('<html>') - str.indexOf('<\/RB:Block_Left>') + str.indexOf('<\/RB:Block_Left>')); 

這一行:

str=str.substring(0,str.indexOf("<RB")-1) + str.substring(str.indexOf("/RB")+15) 
0

你可以做到這一點與HTML元素,並使用jQuery

var ta = $("#code"); // Textarea 
var tag = 'tag'; // Tag name or selector you want to remove 

ta.val(
    $("<div>" + ta.val() + "</div>") // Wrap content of the textarea into a DIV tag 
    .find(tag) // Find all the tags you want to remove 
    .remove() // Remove them 
    .end() // Get back the parent element 
    .html() // Get HTML of the element 
); 

http://jsfiddle.net/w7Rkm/

相關問題