0

我想转换这个:

<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>
4

2 回答 2

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/

于 2013-05-05T11:28:14.630 回答
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)
于 2013-05-05T10:39:45.523 回答