【发布时间】:2017-09-08 14:04:18
【问题描述】:
我尝试创建一个 jquery 代码,它执行以下操作:
如果我将 id 为“ac_inp”的字段设为焦点,则 id 为“ac_sel”的选择字段将被禁用。如果我选择 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)
}
});
【问题讨论】:
-
附加到事件..这只会在加载时发生
-
$( "#target" ).focus(function() { //you code here });喜欢这个 -
那是什么意思?你有我的例子吗?
-
上面给出的条件语句放在
your code part -
如果您可以添加 html 标记,我可以提供更多帮助