[英]JQuery: Can't disable an element for an Ajax response
I have a dynamic dialogue box created by a Ajax return. 我有一个由Ajax返回创建的动态对话框。 I need the the drop list element $('#functionSelect') within the box to change the disability of the input fields if its changes.
我需要框中的下拉列表元素$('#functionSelect')更改输入字段的残障性(如果更改)。 below is my code:
下面是我的代码:
$.ajax({
type: "POST",
async: false,
url: "app_processor.php",
data: {action: "updateCriteriaParameter", criteriaid: criteriaid},
success: function (msg) {
//alert(msg);
if (msg !== 0)
{
$(".dialogDiv").html(msg);
}
}
});
$(document).on('change', '#functionSelect', function () {
functionSelect = $(this).val();
switch (functionSelect) {
case 0:
{
$('#selectPThrehold').attr('disabled', 'disabled');
$('#selectIThrehold').attr('disabled', 'disabled');
}
break;
case 1:
{
$('#selectPThrehold').attr('disabled', 'disabled');
}
break;
case 2:
{
$('#selectIThrehold').attr('disabled', 'disabled');
}
break;
case 5:
{
$('#selectIThrehold').attr('disabled', 'disabled');
}
break;
}
});
However I can't seem to be able to disable other element such as $('#selectPThrehold') 但是我似乎无法禁用其他元素,例如$('#selectPThrehold')
Do anyone have an idea on how i can do this. 有谁知道我该怎么做。
try this 尝试这个
$( document ).ajaxComplete(function() {
$("#functionSelect").change(function () {
$('#selectPThrehold').prop('disabled', true);
});
});
$.ajax({
type: "POST",
async: false,
url: "app_processor.php",
data: {action: "updateCriteriaParameter", criteriaid: criteriaid},
success: function (msg) {
//alert(msg);
if (msg !== 0) {
$(".dialogDiv").html(msg);
$(".dialogDiv").find('#functionSelect').change(function () {
var functionSelect = $(this).val();
$('#selectPThrehold').attr('disabled', 'disabled');
});
}
}
});
Try this 尝试这个
$(document).on('ajax:success', 'body', function (event, xhr, settings) {
functionSelect = $(this).val();
$('#selectPThrehold').attr('disabled', 'disabled');
});
Use ajax:success , this code will be ejecuted when body fires an Ajax query and it returns a success, if ajax query is fired by another link or object put the correct one. 使用ajax:success ,如果body触发了一个Ajax查询,并且另一个链接或对象放入了正确的链接,则该代码将返回成功,并返回成功。
I found the solution. 我找到了解决方案。 I had to use the find() method to get the ajax return descendant element and it worked.
我不得不使用find()方法来获取ajax返回子元素,并且它起作用了。 I have not idea why i couldn't do it directly.
我不知道为什么我不能直接做。
$(document).on('change', '#functionSelect', function () {
functionSelect = $(this).val();
$(".dialogDiv").find('#selectPThrehold').removeAttr('disabled');
$(".dialogDiv").find('#selectIThrehold').removeAttr('disabled');
if (functionSelect == 0)
{
$(".dialogDiv").find('#selectPThrehold').attr('disabled', 'disabled');
$(".dialogDiv").find('#selectIThrehold').attr('disabled', 'disabled');
}
else if (functionSelect == 1)
$(".dialogDiv").find('#selectPThrehold').attr('disabled', 'disabled');
else if (functionSelect == 2)
$(".dialogDiv").find('#selectIThrehold').attr('disabled', 'disabled');
else if (functionSelect == 5)
$(".dialogDiv").find('#selectIThrehold').attr('disabled', 'disabled');
});
thank you. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.