gpt4 book ai didi

javascript - 在代码中使用 .attr ("disabled"时,Jquery Mobile 多选列表禁用选项不起作用

转载 作者:行者123 更新时间:2023-11-30 15:13:13 25 4
gpt4 key购买 nike

我正在尝试编写一些 jquery 代码,当我从另一个选择列表中选择一个值时,它将禁用多选列表中的一个选项。该代码会将 disabled 属性添加到多选列表中,但实际上并没有使该选项变灰。我注意到,要使其真正禁用 jquery mobile 中的选项,我必须将类 .ui-state-disabled 添加到无序列表 li 标记中。不过,我不确定如何实现这一目标。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Elite CTA Create Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link rel="stylesheet" href="../css/themes/Estimates.css" />
<link rel="stylesheet" href="../css/themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script type="application/javascript">
$(document).on("pagecreate", "#page-form1", function() {
$("select").each(function(idx) {
$(this).change(function() {
var value = $(this).val();
if($(this).attr("id") == "Priority")
linkOptions(value);
});
});

$("#lead").change(function() {
var value = $(this).val();
$("#notify option[value='"+value+"']").attr("disabled",true);
$("#notify").trigger("change");
});
});


function linkOptions(priority) {
var cases = {

"Normal": {
"commETA": "2 Days",
"compETA": "1 Week"
},
"High": {
"commETA": "Today",
"compETA": "2 Days"
},
"Severe": {
"commETA": "Today",
"compETA": "Today"
},
"Emergency": {
"commETA": "1 Hour",
"compETA": "Today"
}
};

if (cases[priority]) {
$.each(cases[priority], function(key, value) {
$("#" + key).val(value).trigger("change");
});
}
}
</script>
</head>

<body>
<div data-role="page" id="page-form1" data-theme="a" data-ajax="false">
<div data-role="panel" id="myPanel">
<a href="index.php" class="ui-btn ui-corner-all ui-icon-info ui-btn-icon-left" data-ajax="false">View CTA's</a>
<a href="create.php" class="ui-btn ui-corner-all ui-icon-plus ui-btn-icon-left" data-ajax="false">Create a CTA</a>
</div>
<div data-role="header" data-position="inline">
<a href="#myPanel" class="ui-btn ui-shadow ui-corner-all ui-icon-bars ui-btn-icon-notext ui-btn-inline"></a>
<h1>Elite CTA Form</h1>
</div>
<div data-role="content" id="page-content1" data-theme="a">
<form class="form-signin" id="form1" method="post" action="<?php echo $formaction; ?>">
<h4 class="form-signin-heading" style="text-align: center;">Please describe CTA Below</h4>

<label style="font-weight: bold;">Customer Name:</label>
<input name="Customer_Name" id="Customer_Name" type="text" class="form-control" autofocus required="required"><br />
<label style="font-weight: bold;">Priority Level:</label>
<!-- Selected Priority Level will change the Time for Action and Completion Field Automatically JS Above -->
<select name="Priority" id="Priority" class="selectnoreset" required>
<option value="">Please Select</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Severe">Severe</option>
<option value="Emergency">Emergency</option>
</select><br />
<label style="font-weight: bold;">Project:</label>
<input name="Project" id="Project" type="text" class="form-control"><br />
<label style="font-weight: bold;">Expected Time for Action:</label>
<select name="commETA" id="commETA" class="selectnoreset" required>
<option value="">Please Select</option>
<option value="1 Hour">1 Hour</option>
<option value="Today">Today</option>
<option value="2 Days">2 Days</option>
<option value="1 Week">1 Week</option>
<option value="2 Weeks">2 Weeks</option>
</select><br />
<label style="font-weight: bold;">Expected Time for Completion:</label>
<select name="compETA" id="compETA" class="selectnoreset" required>
<option value="">Please Select</option>
<option value="Today">Today</option>
<option value="2 Days">2 Days</option>
<option value="1 Week">1 Week</option>
<option value="2 Weeks">2 Weeks</option>
<option value="1 Month">1 Month</option>
<option value="Unknown">Unknown</option>
</select><br />
<label style="font-weight: bold;">Description of Issue:</label>
<textarea name="issue" id="issue" required></textarea><br />
<label style="font-weight: bold;">Unknowns About Issue:</label>
<textarea name="unknowns" id="unknowns"></textarea><br />
<label style="font-weight: bold;">People Involved in CTA:</label>
<textarea name="people" id="people"></textarea>
<!-- Assign Main Contact -->
<select name="lead" id="lead" data-iconpos="left" required>
<option value="Mark">Mark</option>
<option value="Dan">Dan</option>
<option value="Alex">Alex</option>
<option value="Brian">Brian</option>
</select>
<!-- End Main Contact -->
<!-- Assign Viewers to the CTA -->
<select multiple="multiple" data-native-menu="false" name="notify[]" id="notify" data-iconpos="left" required>
<option>Assign Viewers</option>
<option value="Mark">Mark</option>
<option value="Dan">Dan</option>
<option value="Alex">Alex</option>
<option value="Brian">Brian</option>
</select>
<!-- End Viewers -->
<br /><br />
<input type="hidden" name="doform" value="doform">
<button name="Submit" id="submit" class="btn btn-lg btn-primary btn-block" type="submit">Submit CTA</button>

<div id="message"></div>
</form>

</div> <!-- /container -->
</body>
</html>

---编辑下面的工作 jQuery 代码我最终混合使用了 deblocker 的代码和我的代码,并得到了以下代码。这确实像我现在期望的那样工作。因此,当我在潜在客户选择列表中选择一个名称时,它会将通知选择列表的多重选择中的选项变灰。选择不同的用户将清除之前选择的用户并仅将选中的用户灰显。再次感谢 deblocker 的出色帮助!

$("#lead").change(function() {
var value = $(this).val();
$("#notify option").removeAttr("disabled");
$("#notify option[value='"+value+"']").attr("disabled",true);
$("#notify").selectmenu("refresh", true);
});

最佳答案

触发器更改确实会影响值,要禁用一个选项,您应该刷新小部件。试试这个:

function toggleOptions() {
var value = "Mark";
if($("#select-custom option[value='"+value+"']").attr("disabled"))
$("#select-custom option[value='"+value+"']").removeAttr("disabled")
else
$("#select-custom option[value='"+value+"']").attr("disabled","disabled");
$("#select-custom").selectmenu("refresh", true);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="content">
<button class="ui-btn ui-corner-all ui-mini" onclick="toggleOptions();">toggle Mark</button>
<div class="ui-field-contain">
<label for="select-custom">Assign Viewers</label>
<select name="select-custom" id="select-custom" multiple="multiple" data-native-menu="false" data-mini="true">
<option value="Mark">Mark</option>
<option value="Dan">Dan</option>
<option value="Alex">Alex</option>
<option value="Brian">Brian</option>
</select>
</div>
</div>
</div>
</body>

</html>

关于javascript - 在代码中使用 .attr ("disabled"时,Jquery Mobile 多选列表禁用选项不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44834239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com