禁用JavaScript中的onclick复选框中的文本框 [英] Disable textbox in onclick checkbox in javascript

查看:54
本文介绍了禁用JavaScript中的onclick复选框中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

我需要帮助来禁用onclick复选框事件中的文本框...
这是我的代码:

Hi everyone......

I need help to disable textbox in onclick checkbox event...
Here is my code:

function ascheckpossible() {
            //debugger;
            var aspossible = document.getElementById("<%=aspossible.ClientID%>");

            if (aspossible.checked == true) {
                document.getElementById("time").style.visibility = "hidden";
                document.getElementById("datetime").style.visibility = "hidden";
                document.getElementById("timedate").style.visibility = "hidden";

            }
            else {
                document.getElementById("time").style.visibility = "visible";
                document.getElementById("datetime").style.visibility = "visible";
                document.getElementById("timedate").style.visibility = "visible";
                document.getElementById("<%=deliveryTime.ClientID %>").value = "";
                document.getElementById("<%=hour.ClientID %>").value = "";
                document.getElementById("<%=min.ClientID %>").value = "";
                document.getElementById("<%=ddltime.ClientID %>").value = "AM";

            }
        }


这里可能是复选框ID,而时间,时间,日期时间是div标签内文本框的ID.

请帮我...


Here aspossible is checkbox id and time,timedate,datetime is id of textbox inside div tag.

Pls help me...

推荐答案

只需在复选框事件onclick的处理程序上调用此函数.请参阅:
http://www.w3schools.com/jsref/dom_obj_event.asp [
Just call this function on a handler of the event onclick of the check box. Please see:
http://www.w3schools.com/jsref/dom_obj_event.asp[^].

<input type="checkbox" id="<%=aspossible.ClientID%>" onclick="ascheckpossible()" />



另外,根据复选框的初始状态,调用此函数以初始化可见性和其他设置.

使用jQuery非常方便.它产生更紧凑和易于支持的代码.请参阅:
http://en.wikipedia.org/wiki/JQuery [ http://jquery.com/ [ ^ ],
http://docs.jquery.com/How_jQuery_Works [ http://api.jquery.com/category/selectors/ [ http://api.jquery.com/category/events/ [ http://api.jquery.com/category/attributes/ [



Also, call this function to initialize visibility and other setting according to the initial state of your check box.

This is very convenient to do with jQuery. It produces much more compact and easy-to-support code. Please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^],
http://docs.jquery.com/How_jQuery_Works[^],
http://api.jquery.com/category/selectors/[^],
http://api.jquery.com/category/events/[^],
http://api.jquery.com/category/attributes/[^].

Two last links embrace all library features you need to know to solve you simple problem: selectors would replace document.getElementById and return jQuery wrappers to any element, and events would replace event properties and handler calls, using attribute functions. All the code is usually written as a single handler of the


(document).ready事件的单个处理程序:

(document).ready event:


(文档).ready(功能(){ myCheckBox =
(document).ready(function() { myCheckBox =


这篇关于禁用JavaScript中的onclick复选框中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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