获取模板复选框名称

发布于 2024-07-25 04:34:33 字数 45 浏览 2 评论 0原文

当 html 模板加载该表单时如何获取复选框名称。 在 Java 脚本中?

How to get the checkbox names when that form is loaded by html template. in Java Script?

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

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

发布评论

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

评论(2

烧了回忆取暖 2024-08-01 04:34:33
var inputs = document.getElementsByTagName('input');
var names = [];
for(var i = 0; i < inputs.length; i++){
    if(inputs[i].type == 'checkbox') names.push(inputs[i].name);
}

如果您不使用 jQuery,则会在数组中为您提供所有他们的名字。 如果您只想对复选框进行操作,您可以转储该 push() 调用并执行您需要的任何操作。

请记住,如果页面上有大量输入,这将是一个缓慢的操作。

var inputs = document.getElementsByTagName('input');
var names = [];
for(var i = 0; i < inputs.length; i++){
    if(inputs[i].type == 'checkbox') names.push(inputs[i].name);
}

Will give you all their names in an array if you're not using jQuery. You can dump that push() call and do whatever you need to there if you just want to operate on checkboxes.

Just remember, if you have a ton of inputs on your page this will be a slow operation.

最冷一天 2024-08-01 04:34:33

如果你了解jquery
这很容易
使用

$(document).ready(function() 
        { 

                $('input:checkbox').each(function() 
                { 
                 do ....   
                }); 

        });

如果你只使用js,则 ,
运行元素并检查 element.type == 'checkbox'

if you know jquery
its easy
use

$(document).ready(function() 
        { 

                $('input:checkbox').each(function() 
                { 
                 do ....   
                }); 

        });

if you use only js,
run over elements and check if element.type == 'checkbox'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文