我正在使用一個簡單的單選按鈕更改事件,因此當單擊一個按鈕時,它應該評估其中一個條件。然而,現在發生的情況是,即使條件是「新攝入量」,'notif'仍然會發射味精。 msg只能在條件=='New Intake with Files'時觸發。單選按鈕更改事件在錯誤的情況下觸發msg
它似乎完全忽略了這種情況。我一直在爲此奮鬥一段時間,如果有人能指出我的錯誤,我將不勝感激。非常感謝。
$(function() {
$('input:radio[name="activity"]').change(function(){
if($(this).val() == 'New Intake with Files'){
//alert("new intake with files");
$('#box_add').on('blur',function(){
$(this).attr('readonly','readonly'); //or use disabled
$('#bfile_add').removeAttr('disabled'); //or use readonly
// SHOULD ONLY DISPLAY IF THIS CONDITION IS MET
notif({
msg: "Please Only input 1 box per file submission. Each box will hold approx 20 files. Thank you.",
type: "boxdstrError",
position: "center",
width: 490,
height: 75,
multiline: true,
timeout: 6000,
opacity: 0.8,
fade: 10,
});
});
} else
if($(this).val() == 'New Intake'){
//alert("new intake");
// SHOULD NOT DISPLAY IF THIS CONDITION IS MET
$('#box_add').on('focus',function(){
$(this).removeAttr('readonly'); //or use disabled attribute
$('#bfile_add').attr('disabled', 'disabled'); //or use readonly
});
}
});
});
HTML
<div class="fieldset">
<h1><span>Activity Type</span></h1>
<p>
<input id="activity" name="activity" class="css-checkbox" type="radio" value="New Intake" checked="checked" />
<label for="activity" class="css-label"></label>
<a href="javascript:void(0)" class="tooltip" title="Choose this option to put new boxes into storage.">New Intake</a>
<br />
<input id="activity1a" name="activity" type="radio" class="css-checkbox" value="New Intake with Files" />
<label for="activity1a" class="css-label"></label>
<a href="javascript:void(0)" class="tooltip" title="Choose this option to put new files into storage together with your box.">New Intake With Files</a>
</p>
</div>
<input class="boxadd" id="box_add" name="box_add[]" type="text" required="required" style="width:250px; height:30px;" />
<input name="bfile_add[]" id="bfile_add" type="text" disabled style="width:250px; height:30px;" />
可以請你也把這裏叫作HTML'代碼? – prog1011 2014-10-04 11:04:08
我同意user357 ...,我已經測試過你的js,它可以正常使用我的單選按鈕 – kellycode 2014-10-04 11:06:39
添加了html。謝謝 – user1532468 2014-10-04 11:07:40