Verify whether a string is a valid HTML tag name

后端 未结 3 946
小蘑菇
小蘑菇 2021-01-21 21:22

How can I find out if a string is a valid HTML tag?

For example: a, or h1, div, or span, ... are a valid HTML tagname. But ar, or abc, or div2, ... are invaild.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 22:03

    Get a list of valid HTML tags (or whatever you want to compare with) and simply do something like:

    function IsValid(s) {
        var tags = ['a', 'p', 'etc...'];
        return tags.indexOf(s) != -1;
    }
    

提交回复
热议问题