Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
使用jquery禁用焦点上的字段_Jquery_Select_Input_Focus - Fatal编程技术网

使用jquery禁用焦点上的字段

使用jquery禁用焦点上的字段,jquery,select,input,focus,Jquery,Select,Input,Focus,我尝试创建jquery代码,该代码执行以下操作: 如果我将id为“ac_inp”的字段置于焦点,则id为“ac_sel”的select字段将被禁用。如果我将id为“ac_sel”的选择字段作为焦点,则id为“ac_inp”的字段将被禁用。但它不起作用。怎么了 $(document).ready(function () { if ($("#ac_inp").is(':focus')) { $("#ac_inp").prop('disabled', false)

我尝试创建jquery代码,该代码执行以下操作:

如果我将id为“ac_inp”的字段置于焦点,则id为“ac_sel”的select字段将被禁用。如果我将id为“ac_sel”的选择字段作为焦点,则id为“ac_inp”的字段将被禁用。但它不起作用。怎么了

$(document).ready(function () {
    if ($("#ac_inp").is(':focus')) {
        $("#ac_inp").prop('disabled', false)
        $("#ac_sel").prop('disabled', true)
    }
    if ($("#ac_sel").is(':focus')) {
        $("#ac_inp").prop('disabled', true)
        $("#ac_sel").prop('disabled', false)
    }
});

在代码段中,您准备了一个在文档加载时运行一次的脚本

在这种情况下,您需要为焦点创建事件,而不是一个不再运行的检查

<> P>如果你有这种基本的疑虑,请考虑在入门代码之前认真学习一本入门级的书,否则你会浪费很多时间,理解基本概念是非常重要的。
<script>
$(document).ready(function () {

  $("#ac_inp").focus(function() {
     $(this).prop('disabled', false);
     $("#ac_sel").prop('disabled', true);
  });

  $("#ac_sel").focus(function() {
    $(this).prop('disabled', false);
    $("#ac_inp").prop('disabled', true);
  });

});
</script>

$(文档).ready(函数(){
$(“#ac#u inp”).focus(函数(){
$(this.prop('disabled',false);
$(“#ac#u sel”).prop('disabled',true);
});
$(“#ac#u sel”).焦点(函数(){
$(this.prop('disabled',false);
$(“#ac#U inp”).prop('disabled',true);
});
});

附加到事件。。这只会在加载
$(“#target”)时发生像这样,这意味着什么?你有没有给我举个例子?在上面的
代码部分中放置你的条件语句
,如果你能添加html标记,我可以提供更多帮助