dongrong5189 2016-09-16 06:41
浏览 35
已采纳

选择选项后禁用输入字段

_this is my UI

<script>
    function changeTextbox()
    {
        $("#service_request").on("change", function(){
        if ($(this).val() == "Group Code")
        {
        $("#employee_id").attr("disabled","disabled");
        } else {
         $("#employee_id").removeAttr("disabled");
       }

  });
}

_that is my script

<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;?>

_this is how my select options goes

 <input style="border-radius:10px;width:425px;height:35px;" type="text" id="employee_id"  name="assign_to" onkeyup="autocomplet()" placeholder="Approver" onchange="changeTextbox()"/>

_this is for my input text field

enter image description here _its the value in my inspect element

** _I don't know what's going on with this code, the Approver text field should be disabled, if the Group Code service is selected, but it turn's out to be not working, someone help me please :D**

  • 写回答

3条回答 默认 最新

  • duannue2455 2016-09-16 06:59
    关注

    The textbox disabled property is dependent on select change event so onchange for textbox is useless so remove the function changeTextbox() . In your script on select change event do

    $(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); 
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料