Home  >  Article  >  Web Front-end  >  jquery realizes that the control is unavailable after canceling the check box, but is available when selected (code)

jquery realizes that the control is unavailable after canceling the check box, but is available when selected (code)

不言
不言Original
2018-08-16 12:01:501646browse

The content of this article is about the jquery implementation of the control being unavailable after canceling the check box. It is available when selected (code). It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. help.

Tag content

<div class="box">
        请编写javascript代码,完成如下功能要求:<br />
        1.取消复选款后,要求促销价格、促销开始结束日期3个控件不可用。<br />
        2.选中复选框后,要求促销价格、促销开始结束日期3个控件可用。
    </div>
    <div class="box">
    
        <table id="table1" class="mytable">
            <tr>
                <td>是否促销:</td>
                <td><input type="checkbox" id="chkPromote" /></td>
            </tr>
            <tr>
                <td>
                    促销价格:
                </td>
                <td>
                    <input type="text" id="txtPromotePrice" />
                </td>
            </tr>
            <tr>
                <td>
                    促销日期:
                </td>
                <td>
                    <input type="text" id="txtStart" />-
                    <input type="text" id="txtEnd" />
                </td>
            </tr>
        </table>
    </div>
Jquery内容
<script>
$(function () {

            $("input[type=text]").attr("disabled", true).val("不可使用");
$("input[type=checkbox]").click(function () {
               
                var $cr = $("input[type=checkbox]");
                if ($cr.is(":checked")) {
                    
                    $("input[type=text]").attr("disabled", false).val("可以使用");
                }
                else {
                    
                    $("input[type=text]").attr("disabled", true).val("不可使用");
                }
            });

        });
</script>

Related recommendations:


The above is the detailed content of jquery realizes that the control is unavailable after canceling the check box, but is available when selected (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn