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
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn