首頁  >  文章  >  web前端  >  JavaScript偵測字串中是否含有html標籤實作方法_javascript技巧

JavaScript偵測字串中是否含有html標籤實作方法_javascript技巧

WBOY
WBOY原創
2016-05-16 15:52:141635瀏覽

功能代碼

複製程式碼 程式碼如下:

/**
 * 字串是否含有html標籤的偵測
 * @param htmlStr
 */
function checkHtml(htmlStr) {
    var  reg = /] >/g;
    return reg.test(htmlStr);
}

demo
script:
複製程式碼 程式碼如下:

/**
 * 字串是否含有html標籤的偵測
 * @param htmlStr
 */
function checkHtml(htmlStr) {
    var  reg = /] >/g;
    return reg.test(htmlStr);
}
window.onload=function(){
    var html=document.querySelector('#box').innerHTML;
    alert(checkHtml(html))
}

html
複製程式碼 程式碼如下:

 

        sdfsdf
       

        sdfsdf
   

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn