Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据下拉选择清除和启用/禁用字段_Javascript_Jquery_Html - Fatal编程技术网

Javascript 根据下拉选择清除和启用/禁用字段

Javascript 根据下拉选择清除和启用/禁用字段,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试清除字段的值,并根据下拉选择值启用/禁用字段。当前,字段的启用/禁用功能正在工作,但在清除字段时,该功能不工作。 我附上了html代码中的代码片段,根据状态值,其他字段(如sc、sc-risted等)应该启用。根据状态值更改,应清除“上一次启用”字段。甚至提交按钮也应该基于此启用。有什么帮助吗 Html代码段: <div class="col-md-6"> <div class="form-group"> <label class="co

我正在尝试清除字段的值,并根据下拉选择值启用/禁用字段。当前,字段的启用/禁用功能正在工作,但在清除字段时,该功能不工作。 我附上了html代码中的代码片段,根据状态值,其他字段(如sc、sc-risted等)应该启用。根据状态值更改,应清除“上一次启用”字段。甚至提交按钮也应该基于此启用。有什么帮助吗

Html代码段:

<div class="col-md-6">
   <div class="form-group">
      <label class="control-label col-lg-4">Status:<span class="Imp">*</span></label>
      <div class="col-lg-8">
         @Html.DropDownList("Status", new SelectListItem[] { (new SelectListItem() { Text = "SC", Value = "SC" }), (new SelectListItem() { Text = "PO", Value = "PO" }), (new SelectListItem() { Text = "INV", Value = "INV" }) }, "-- Select Status --", new { @class = "form-control", id = "Status" })
      </div>
   </div>
</div>
<div class="row top-buffer">
   <div class="col-md-6">
      <div class="form-group">
         <label class="control-label col-lg-4">SC Raised:<span class="Imp">*</span></label>
         <div class="col-lg-8">
            <div class='input-group date' id='SCRaisedDatePicker'>
               <input type='text' class="form-control" name="SCRaised" placeholder="MM/DD/YYY" id="SCRaised" />
               <span class="input-group-addon">
               <span class="fa fa-calendar">
               </span>
               </span>
            </div>
         </div>
      </div>
   </div>
   <div class="col-md-6">
      <div class="form-group">
         <label class="control-label col-lg-4">SC:<span class="Imp">*</span></label>
         <div class="col-lg-8">
            @Html.TextBoxFor(model => model.detailsConfig.SC, new { onkeypress = "return isNumberKey(event)", @class = "form-control", id = "SC" })
         </div>
      </div>
   </div>
</div>
<div class="row top-buffer">
   <div class="col-md-6">
      <div class="form-group">
         <label class="control-label col-lg-4">PO#:<span class="Imp">*</span></label>
         <div class="col-lg-8">
            @Html.TextBoxFor(model => model.detailsConfig.PO, new { onkeypress = "return isNumberKey(event)", @class = "form-control", id = "PO" })
         </div>
      </div>
   </div>
   <div class="col-md-6">
      <div class="form-group">
         <label class="control-label col-lg-4">PO Out:<span class="Imp">*</span></label>
         <div class="col-lg-8">
            <div class='input-group date' id='PODatePicker'>
               <input type='text' class="form-control" name="POOut" placeholder="MM/DD/YYY" id="POOut" />
               <span class="input-group-addon">
               <span class="fa fa-calendar">
               </span>
               </span>
            </div>
         </div>
      </div>
   </div>
</div>
<div class="modal-footer">
   <input type="submit" id="btnSubmit" value="Submit" class="btn btn-lg btn-success" />
</div>

我在您的代码片段中注意到的一点是,您使用的getElementById不正确

document.getElementById("#PO").value = "";

作为一个参数,您应该提供不带的id。

我在您的代码片段中注意到的一点是,您使用的getElementById不正确

document.getElementById("#PO").value = "";

作为一个参数,您应该提供不带参数的id。

要从输入中删除该值,请使用jquery val函数将空字符串作为aprama传递


$'scrasied'.val

要从输入中删除值,请使用jquery val函数将空字符串作为aprama传递


$'scrasied'.val

给你一个解决方案

$'Status'.change函数{ 切换$this.find'option:selected'。文本{ 案例“-选择状态-”: $'scrasited,SC,PO,POOut'。prop'disabled',true; 打破 案例“SC”: $'scrasited,SC'。prop'disabled',false; $PO,POOut.val; $'PO,POOut'.prop'disabled',true; 如果$'scrased'.val.length>0&&$'SC'.val.length>0{ $input[type=submit].propdisabled,false; } 打破 个案"PO": $'PO,POOut'.prop'disabled',false; $已注销,SC'.val; $'scrasted,SC,ItemArrival'。prop'disabled',true; 如果$'PO'.val.length>0&&$'POOut'.val.length>0{ $input[type=submit].propdisabled,false; } 打破 }
}; 给你一个解决方案

$'Status'.change函数{ 切换$this.find'option:selected'。文本{ 案例“-选择状态-”: $'scrasited,SC,PO,POOut'。prop'disabled',true; 打破 案例“SC”: $'scrasited,SC'。prop'disabled',false; $PO,POOut.val; $'PO,POOut'.prop'disabled',true; 如果$'scrased'.val.length>0&&$'SC'.val.length>0{ $input[type=submit].propdisabled,false; } 打破 个案"PO": $'PO,POOut'.prop'disabled',false; $已注销,SC'.val; $'scrasted,SC,ItemArrival'。prop'disabled',true; 如果$'PO'.val.length>0&&$'POOut'.val.length>0{ $input[type=submit].propdisabled,false; } 打破 }
}; 使用change-$Status.changefunction的说明 在-$'Status'上使用。在'change'上使用函数{}并用于清除值

$('#PO').val("") 

而不是document.getElementByIdPO.value=;正如mic4ael前面提到的,无需在javascript代码中使用选择

使用change的指令-$Status.changefunction 在-$'Status'上使用。在'change'上使用函数{}并用于清除值

$('#PO').val("") 

而不是document.getElementByIdPO.value=;正如mic4ael前面提到的,无需在javascript代码中使用选择

即使我在Scrasied和SC中输入值,提交也不会被启用。其余工作正常:以上问题的任何帮助请在if语句中添加console.log,并检查它是否进入if语句。我检查了它没有进入if语句,甚至在控制台中抛出错误无法读取未定义的属性“length”。即使在我编辑代码之后,您也收到了错误???“SC”和“PO”两个选项都给出了相同的错误?代码中的编辑是什么?我检查了SC,发现错误即使我在Scrased和SC中输入值,提交也不会被启用。其余工作正常:以上问题的任何帮助请在if语句中添加console.log,并检查它是否进入if语句。我检查了它没有进入if语句,甚至在控制台中抛出错误无法读取未定义的属性“length”。即使在我编辑代码之后,您也收到了错误???“SC”和“PO”两个选项都给出了相同的错误?代码中的编辑是什么?我检查了SC,我得到了错误