如何启用日期和文本框,如果我选中复选框,因为如果选中复选框,它也将禁用

时间:2017-11-03 02:29:57

标签: javascript jquery html

所以,让我们说这是我的html,当我检查其行中的复选框时它仍然禁用,所以如果我检查相应的复选框我需要启用它们

<tr><th><input type="checkbox" placeholder="forOfficialUse"
name="progress" 
id="progress1" value="1" tabIndex="1" onClick="ckChange(this)"> For 
Official Use </br></th>

<th><input type="checkbox" placeholder="forSample" name="progress" 
id="progress2" value="1" tabIndex="1" onClick="ckChange(this)"> For sample 
</th></tr>

<tr><th><input type="checkbox" placeholder="toBeReturn" name="progress" 
id="progress3" value="1" tabIndex="1" onClick="ckChange(this)"> For use in 
showroom to be return on <input type="date" name="progress" id="progress3" 
placeholder="date"s></th>

<th><input type="checkbox" placeholder="OnLoan" name="progress" 
id="progress4" value="1" tabIndex="1" onClick="ckChange(this)"> On Loan 
</th></tr>

<tr><th><input type="checkbox" placeholder="toBeNotReturn" name="progress" 
id="progress5" value="1" tabIndex="1" onClick="ckChange(this)"> For use in 
showroom not to be returned </th>

<th><input type="checkbox" placeholder="Other" name="progress" 
id="progress6" value="1" tabIndex="1" onClick="ckChange(this)"> Other 
<input type="text" name="progress" id="progress6" placeholder="State the 
Purpose"></th></tr>

<script>
    function ckChange(ckType)
    {
        var ckName = document.getElementsByName(ckType.name);
        var checked = document.getElementById(ckType.id);

        if (checked.checked) 
        {
            for(var i=0; i < ckName.length; i++)
            {
                if(!ckName[i].checked)
                {
                    ckName[i].disabled = true;
                }
                else
                {
                    ckName[i].disabled = false;
                }
            } 
        }
        else 
        {
            for(var i=0; i < ckName.length; i++)
            {
                ckName[i].disabled = false;
            } 
        }    
    }
</script>

如果我选中相应行中的复选框,我将如何启用日期和文本框?

0 个答案:

没有答案