系统的 HTML 标签验证

发布于 2024-10-08 04:36:49 字数 254 浏览 0 评论 0原文

有没有离线工具可以验证某些标签是否具有特定属性?

我正在寻找可以验证所有:

  • form 标签是否具有 name 属性的东西。
  • divspan 标签至少有一个 idclass 属性。

tidy 是否有一个晦涩的选项供您指定此类内容?

Is there an offline tool that can verify whether certain tags possess particular attributes?

I'm looking for something that can verify that all:

  • form tags have a name attribute.
  • div, and span tags have at least an id or class attribute.

Does tidy have an obscure option where you could specify such things?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走野 2024-10-15 04:36:49

如果 jQuery 在您的页面上可用,您可以像这样简单快速地进行验证。

    $('form').each(function(){
        if ($(this).attr('name') === undefined) {
            alert('There is at least one form with no name.');
        }
    });
    $('div').each(function(){
        if ($(this).attr('id') === undefined) {
            alert('There is at least one div with no id.');
        }
    });

simply and quickly you can do your validations like this if jQuery is available on your page.

    $('form').each(function(){
        if ($(this).attr('name') === undefined) {
            alert('There is at least one form with no name.');
        }
    });
    $('div').each(function(){
        if ($(this).attr('id') === undefined) {
            alert('There is at least one div with no id.');
        }
    });

洋洋洒洒 2024-10-15 04:36:49

这也是一个非 jQuery 解决方案示例

var arr = document.getElementsByTagName('div');
var flag = false;
for (var i = 0, len = arr.length; i < len; i++) {
    if (arr[i].getAttribute('id') == null) {
        flag = true;
        break;
    }
}
if (flag) {
    alert('There is at least one div with no name.');
}

also this is a non-jQuery solution example

var arr = document.getElementsByTagName('div');
var flag = false;
for (var i = 0, len = arr.length; i < len; i++) {
    if (arr[i].getAttribute('id') == null) {
        flag = true;
        break;
    }
}
if (flag) {
    alert('There is at least one div with no name.');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文