我有一組嵌套的If/Else語句,旨在確定機器,客戶和部件源的類型,以便將使用該站點的人員指向正確的部門訂購部件。這裏是代碼我有:測試JQuery中的單選按鈕檢查狀態無法正常工作
$('#partName').catcomplete({
minLength: 2,
source: data,
select: function (event, ui) {
$("#partNumber").text(ui.item.Number);
$("#partDesc").text(ui.item.PartDesc);
// Determine machine type
if (ui.item.Type == "All Machines") {
$("#machineType").html("<div class='ui-widget'><div class = 'ui-state-highlight ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 6px;'></span> Message for parts that go to all machines</p></div></div>");
}
else if (ui.item.Type == "Machine Type 1") {
$("#machineType").html("<div class='ui-widget'><div class = 'ui-state-error ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: 6px;'></span> Message for parts ONLY for Machine Type 1</p></div></div>");
}
else if (ui.item.Type == "Machine Type 2") {
$("#machineType").html("<div class='ui-widget'><div class = 'ui-state-error ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: 6px;'></span> Message for parts ONLY for Machine Type 2 </p></div></div>");
}
// How determine who to transfer call to
if ($('#radio1').is(':checked')){
if (ui.item.type == "Machine Type 1" || "All Machines") {
if (ui.item.Source == 1) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-highlight ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 6px;'></span> Text containing extension #1</p></div></div>");
}
if (ui.item.Source == 2) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-highlight ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 6px;'></span> Text containing extension #2</p></div></div>");
}
}
if (ui.item.type == "Machine Type 2") {
if (ui.item.Source == 1) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-highlight ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 6px;'></span> Text containing extension #1</p></div></div>");
}
if (ui.item.Source == 2) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-highlight ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 6px;'></span> Text containing extension #2</p></div></div>");
}
}
}
else {
if (ui.item.type == "Machine Type 1") {
if (ui.item.Source == 1) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-error ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: 6px;'></span> This machine and its parts are not available to this customer. Please try your search again.</p></div></div>");
}
if (ui.item.Source == 2) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-error ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: 6px;'></span> This machine and its parts are not available to this customer. Please try your search again.</p></div></div>");
}
}
if (ui.item.type == "Machine Type 2" || "All Machines") {
if (ui.item.Source == 1) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-highlight ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 6px;'></span> Text containing extension #3</p></div></div>");
}
if (ui.item.Source == 2) {
$("#partSource").html("<div class='ui-widget'><div class = 'ui-state-highlight ui-corner-all' style='margin=top:5px;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 6px;'></span> Text containing extension #4</p></div></div>");
}
}
}
含有形式,單選按鈕HTML的嵌段:
<div id="radio">
<strong>Select Machine: </strong>
<input type="radio" value="fsa" id="radio1" name="radio" checked><label for="radio1">Customer Type 1</label>
<input type="radio" value="evo" id="radio2" name="radio"><label for="radio2">Customer Type 2</label>
</div>
<label for="partName"><strong>Part Name:</strong></label>
<input id="partName" size="50">
<input class="ui-state-default ui-corner-all" type="button" id="clearPartName" onClick="clear_all()" value="Clear Search">
</p>
<div id="partData">
<div id="partNumberField">
<p><strong>PBS Part Number:</strong></p>
<div style="margin: 2px" class="ui-widget-content" id="partNumber"> </div>
</div>
<div id="partDescField">
<p><strong>Part Description:</strong></p>
<div style="margin: 2px" class="ui-widget-content" id="partDesc"> </div>
</div>
<div id="machineTypeField">
<div style="margin: 2px" id="machineType"> </div>
</div>
<div id="partObtainField">
<p><strong>Source for Part:</strong></p>
<div style="margin: 2px" id="partSource"> </div>
</div>
</div>
然而,if ($('#radio1').is(':checked'))
似乎不正常工作,選擇客戶類型2(這將使#radio1
的狀態爲false),並且機器類型1不返回錯誤消息,指示該機器及其部件對選定客戶不可用。
我非常困惑,試圖測試這個單選按鈕狀態,因爲我沒有發現似乎在我實際運行頁面時能正常工作。
http://stackoverflow.com/questions/596351/how-can-i-get-which-radio-is-selected-via-jquery – AuthorProxy
你是什麼意思「因爲選擇客戶類型1會使#radio1的狀態爲false「?從它的外觀來看,它應該是真的,如果它被選中? 「機器類型1」的收音機在哪裏?你可以用http://jsfiddle.net來說明問題嗎? –
@ AlexV.Kostyukov - 仍然不會觸發最外層if語句的第二部分。 – Matthew