簡體   English   中英

刪除HTML標簽並在標簽后插入空格?

[英]removing HTML tags and inseting space after tag?

<div><p><input type="radio" name="choice"><span>text1</span></p>
<p><input type="radio" name="choice"><span>text2</span></p>
<p><input type="radio" name="choice"><span>text3</span></p>
<p><input type="radio" name="choice"><span>text4</span></p>

</div>

我想刪除html標簽,也需要在換行中獲取所有數據,我可以使用以下代碼獲取數據,但是如何在它們之間插入行呢?

在一行中沒有標簽的文本代碼?

function getInfo(Description) {
  return Description.replace(/(<([^>]+)>)/ig,"");
}

我想要輸出像

text1
text2
text3

@kiran:也許像-

<script type="text/javascript">
    function getInfo(Description) {
        var tmp = Description.replace(/(<([^>]+)>)/ig,"");
        return tmp.replace(/\n/g, "<br>")
    }
    var somevar;
    somevar  = "<div><p><input type=\"radio\" name=\"choice\"><span>text1</span></p>\n";
    somevar += "<p><input type=\"radio\" name=\"choice\"><span>text2</span></p>\n";
    somevar += "<p><input type=\"radio\" name=\"choice\"><span>text3</span></p>\n";
    somevar += "<p><input type=\"radio\" name=\"choice\"><span>text4</span></p>\n";

    document.write(getInfo(somevar));
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM