使用If条件取决于单选框禁用输入(IE问题)

时间:2018-01-07 06:48:58

标签: javascript html5 knockout.js

<fieldset class="form-horizontal radiogroup" style="margin-left:-10px"> <label style="font-weight:normal" id="item4" class="col-sm-12" style="margin-top: 20px; margin-left:0px;">1.a. Is the anticipated RLF lending area different from the geographic area described in ED-900, Section B.1?</label> <div class="col-sm-3 checkboxcluster" style="margin-top: 0px; margin-left: 15px" data-bind="css:lendingAreaDifferentCSS, attr: { title: lendingAreaDifferentToolTip1}"> <div class="form-group-sm" data-bind="attr: { title: lendingAreaDifferentToolTip}"> <label class="radio-label" for="lendingAreaDifferentYes" style="font-weight:normal;"> <input name="" type="radio" value="Y: Yes" id="lendingAreaDifferentYes" data-bind="checked: lendingAreaDifferent" /> Yes</label> </div> <div class="form-group-sm" data-bind="attr: {title: lendingAreaDifferentToolTip}"> <label class="radio-label" for="lendingAreaDifferentNo" style="font-weight: normal;"> <input name="" type="radio" id="lendingAreaDifferentNo" value="N: No" data-bind="checked: lendingAreaDifferent" /> No </label> </div> </div> <fieldset class="form-horizontal radiogroup" style="margin-left: -15px" data-bind="enable: lendingAreaDifferent() == 'Y: Yes'"> <div class="col-sm-12" style="margin-left:5px; margin-top: 20px"> <label style=" width: 66%; font-weight:normal; margin-left: -15px" class="surveyquestion">1.b. If Yes, define the anticipated RLF lending area.</label> <br> <textarea style="width:90%; " id="lendingArea" maxlength="8000" data-bind="css: lendingAreaCSS , attr: { title: lendingAreaToolTip }, event: {focusout: checkLostFocus.bind($root, $data, 'lendingArea')}, value: lendingArea"></textarea> </div> </fieldset> </fieldset>

如果上面的无线电按钮没有选择,我希望在默认情况下禁用(禁用)文本区域landingArea。当选择为NO时,它也被禁用,这意味着值“N:No”。当从单选按钮中选择为YES时,它唯一一次处于活动状态并启用,这意味着值“Y:是”。我在所有浏览器中都得到了这个权利,但在IE中它没有禁用它

1 个答案:

答案 0 :(得分:0)

  

我找到的解决方案是:我将函数添加到javascript文件:document.getElementById(&#34; lendingArea&#34;)。disabled = true;谢谢!

   lendingAreaDifferent.subscribe(function (newValue) {
        lendingAreaCSS('');

    //CountryName('');

    if (newValue != undefined) {
        //CountryName(newValue.Name);
        if (lendingAreaDifferent() == "Y: Yes") {

            lendingAreaCSS('requiredfield');



        } 
        if (lendingAreaDifferent() == "N: No") {

            lendingArea('');
            document.getElementById("lendingArea").disabled = true;



        }
        else{
          document.getElementById("lendingArea").disabled = false;
        }

        if (loading == false) {
            sendCommand('SAVE');
        }
    }

});