_这是我的界面
<script>
function changeTextbox()
{
$("#service_request").on("change", function(){
if ($(this).val() == "Group Code")
{
$("#employee_id").attr("disabled","disabled");
} else {
$("#employee_id").removeAttr("disabled");
}
});
}
_那是我的脚本
<select style="width:199px;border-radius:10px;" id="service_request" name="service_request" class="form-control" onchange="showUser(this.value)">
<option value="Default Request" selected disabled>Default Request Service</option>
<?php if(isset($records)): foreach($records as $row):?>
<option value="<?php echo $row->service_group;?>"><?php echo $row->service_group;?></option>
<?php endforeach;?>
<?php else:?>
<p>Request Service not available</p>
<?php endif;?>
_这就是我选择选项的方式
<input style="border-radius:10px;width:425px;height:35px;" type="text" id="employee_id" name="assign_to" onkeyup="autocomplet()" placeholder="Approver" onchange="changeTextbox()"/>
_这是我的输入文本字段
** _我不知道这段代码是怎么回事,如果选择了组代码服务,应该禁用 Approver 文本字段,但事实证明它不起作用,请有人帮助我:D**
最佳答案
文本框禁用属性依赖于选择更改事件,因此文本框的 onchange 无用,因此删除函数 changeTextbox()
。在选择更改事件的脚本中执行
$(document).ready(function(){
$('#service_request').on('change',function(){
if($(this).val() == 'Group Code' )
//$("#employee_id").attr("disabled", "disabled");
$("#employee_id").prop("disabled", true);
else
//$("#employee_id").removeAttr("disabled");
$("#employee_id").prop("disabled", false);
});
});
关于javascript - 选择选项后禁用输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39525211/