用于启用/禁用输入元素的脚本? [英] Script to enable/disable input elements?

查看:91
本文介绍了用于启用/禁用输入元素的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道脚本是否有可能通过某种切换按钮启用/禁用页面上的所有输入元素。



我用Google搜索但是没有除此之外找不到任何有用的东西:



http://www.codetoad.com/javascript/enable_disable_form_element.asp
但是我不知道如何为切换编辑它。



  $()。ready(function(){$('#clicker')。click(function(){$('input')。each(function(){if($(this).attr( 'disabled')){$(this).removeAttr('disabled');} else {$(this).attr({ '禁用':'禁用'}); }}; });});  

 < script src = https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js\"></script><input type ='text'>< / input>< input type ='text'>< / input>< input type ='text'>< / input>< div id ='clicker'style ='background-color:#FF0000;高度:40像素;宽度:100px;'>< / div>  


I'm wondering if it's possible for a script to enable/disable all input elements on the page with some sort of toggle button.

I googled it but didn't find anything too useful except for this:

http://www.codetoad.com/javascript/enable_disable_form_element.asp but I'm not sure how to edit it for the toggle.

解决方案

A working example:

$().ready(function() {


    $('#clicker').click(function() {
        $('input').each(function() {
            if ($(this).attr('disabled')) {
                $(this).removeAttr('disabled');
            }
            else {
                $(this).attr({
                    'disabled': 'disabled'
                });
            }
        });
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<input type='text'></input>
<input type='text'></input>
<input type='text'></input>


<div id='clicker' style='background-color:#FF0000; height:40px; width:100px;'></div>

这篇关于用于启用/禁用输入元素的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆