【问题标题】:Reset disabled input field's value重置禁用输入字段的值
【发布时间】:2016-08-27 03:19:09
【问题描述】:

HTML:

<template name="Dep_Con">
<input disabled={{SBD_Dep_Con}} class="input" value="" type="text"/>
</template>  

Js:

Template.registerHelper("SBD_Dep_Con", function() {
    var returnval = "n";
    const ans = Session.get('chosen')
    const product = ProductList.findOne({ product: ans});
    console.log("product.dep_con:" + product.department_contact)
    if(product.department_contact == "N/A") {return true}
    else {return false}
});  

我已成功启用/禁用 html 中的输入字段(文本),这取决于使用上述代码的另一个保管箱的值。

问题是当输入字段在启用时被填充然后被禁用时,填充的值仍然存在。当“禁用”状态发生变化时,有没有办法重置输入字段的值?还是我看错了方向(即表单有办法不从禁用的输入字段中检索值)?

【问题讨论】:

    标签: meteor


    【解决方案1】:

    您可以在使用 jquery 禁用输入字段之前清除它。我稍微修改了你的代码。

    <template name="Dep_Con">
        <input disabled={{SBD_Dep_Con}} class="input" id="input_field" value="" type="text"/>
    </template> 
    

    JS 文件

    Template.registerHelper("SBD_Dep_Con", function() {
        var returnval = "n";
        const ans = Session.get('chosen');
        const product = ProductList.findOne({ product: ans});
        console.log("product.dep_con:" + product.department_contact)
        if(product.department_contact == "N/A") {
            $('#input_field').val('');   //Add this corresponding to id.
           return true   }
        else {
        return false}
    });
    

    【讨论】:

    • 成功了,谢谢!我以前有同样的事情,但没有工作,认为这不是办法,只是意识到我错过了'#'
    猜你喜欢
    • 2020-11-27
    • 2018-09-25
    • 2011-05-02
    • 2012-11-04
    • 2017-05-19
    • 2016-03-20
    • 1970-01-01
    相关资源
    最近更新 更多