【问题标题】:Change checkbox to checked when text field value changes当文本字段值更改时,将复选框更改为选中
【发布时间】:2015-01-27 10:25:13
【问题描述】:

我有一个慈善页面,其中包含添加额外捐款的选项。捐赠者必须选中复选框,然后在文本字段中添加金额才能添加。但似乎有些人在文本字段中添加金额时忽略了复选框,因此不包括额外的捐赠。

这是我的 HTML 代码--

<input alt="Additional Donation" id="other_donation_check" onclick="UpdateCost()" 
type="checkbox" value="on" />
I would like to make an (additional) <em><strong>tax-deductible</strong></em> 
donation of $<input id="other_donation_amount" name="other_donation_amount" 
onblur="UpdateCost()" onchange="UpdateCost()" onclick="UpdateCost()" 
onfocus="UpdateCost()" size="8" type="text" />

如果在文本字段中添加了任何金额,我可以在检查复选框的代码中添加什么?

【问题讨论】:

    标签: jquery text checkbox checked donations


    【解决方案1】:

    试试:

    <script>
        function check() {
            document.getElementById('other_donation_check').checked = true;
        }
    </script>
    
    <input alt="Additional Donation" id="other_donation_check" onclick="UpdateCost()" type="checkbox" />
    I would like to make an (additional) <em><strong>tax-deductible</strong></em>
    donation of $<input id="other_donation_amount" name="other_donation_amount" onkeyUp="check()"  size="8" type="text" />
    

    小提琴:http://jsfiddle.net/jzz0sapc/

    【讨论】:

    • 效果很好,M. Page。但它似乎引入了一个不同的小问题。
    猜你喜欢
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多