Function code
/**
* Detection of whether a string contains html tag
* @param htmlStr
*/
function checkHtml(htmlStr) {
var reg = /<[^>] >/g;
Return reg.test(htmlStr);
}
demo
script:
/**
* Detection of whether a string contains html tag
* @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