我正在創建選擇框,並且我爲jquery.it中的選擇框編寫了更改函數。但我的問題是,當我在選擇框中移動光標選項時,沒有選擇任何選項,我點擊了選擇框旁邊。但改變功能調用我不知道如何解決這個問題我的代碼被賦予波紋管jQuery中的onchange問題
和我的小提琴被http://jsfiddle.net/6mhed8yL/
<select name="selecting" id="selecting" >
<option selected="selected" >--Control--</option>
<option id="Select All ">Select All</option>
<option id="Remove All " >Remove All</option>
<option id="Sample Questions" >Sample Questions</option>
<option id=" User Added Questions">User Added Questions</option>
<option id="Show All Questions" >Show All Questions</option>
</select>
jQuery的
$('#selecting').change(function(){
alert("check");
var opt=$('#selecting').val();
var url="";
alert("option is"+opt);
// $("#selecting option:selected").removeAttr('disabled');
//$("#selecting option:disabled").val(opt);
//$("#selecting option[value=" + opt + "]").attr('disabled', 'disabled');
if(opt=="Select All")
{
$('input:checkbox').prop('checked', true);
$("select option:contains('Select All')").attr("disabled","disabled");
$("select option:contains('Remove All')").removeAttr("disabled");
$("select option:contains('Sample Questions')").removeAttr("disabled");
$("select option:contains('User Added Questions')").removeAttr("disabled");
$("select option:contains('Show All Questions')").removeAttr("disabled");
}
else if(opt=="Remove All")
{
$("input:checkbox").prop("checked", false);
$("select option:contains('Remove All')").attr("disabled","disabled");
$("select option:contains('Select All')").removeAttr("disabled");
$("select option:contains('Sample Questions')").removeAttr("disabled");
$("select option:contains('User Added Questions')").removeAttr("disabled");
$("select option:contains('Show All Questions')").removeAttr("disabled");
}
else if(opt=="Sample Questions")
{
$("select option:contains('Sample Questions')").attr("disabled","disabled");
$("select option:contains('Select All')").removeAttr("disabled");
$("select option:contains('Remove All')").removeAttr("disabled");
$("select option:contains('User Added Questions')").removeAttr("disabled");
$("select option:contains('Show All Questions')").removeAttr("disabled");
url = "SampleQuestions.jsp";
alert("sample");
/* if (window.XMLHttpRequest)
req = new XMLHttpRequest();
else if (window.ActiveXObject)
req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET", url, true);
req.onreadystatechange =callback;
req.send(null); */
}
else if(opt=="User Added Questions")
{
$("select option:contains('User Added Questions')").attr("disabled","disabled");
$("select option:contains('Select All')").removeAttr("disabled");
$("select option:contains('Remove All')").removeAttr("disabled");
$("select option:contains('Sample Questions')").removeAttr("disabled");
$("select option:contains('Show All Questions')").removeAttr("disabled");
$("select option:contains('Show All Questions')").removeAttr("disabled");
url="UserAddedQuestion.jsp";
alert("user");
/* if (window.XMLHttpRequest)
req = new XMLHttpRequest();
else if (window.ActiveXObject)
req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET", url, true);
req.onreadystatechange =callback;
req.send(null);
*/
}
else if(opt=="Show All Questions")
{
$("select option:contains('Show All Questions')").attr("disabled","disabled");
$("select option:contains('Select All')").removeAttr("disabled");
$("select option:contains('Remove All')").removeAttr("disabled");
$("select option:contains('Sample Questions')").removeAttr("disabled");
$("select option:contains('User Added Questions')").removeAttr("disabled");
url="ShowAllQuestions.jsp";
alert("all");
/* if (window.XMLHttpRequest)
req = new XMLHttpRequest();
else if (window.ActiveXObject)
req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET", url, true);
req.onreadystatechange =callback;
req.send(null);
*/
}
});
你的提琴
檢查需要選擇選項'沒有包裝 - 在
' – Neverever 2014-12-19 06:25:33你描述的不是發生在我什麼,你的原代碼應該可以正常工作。 – Neverever 2014-12-19 06:27:02
所有那些重複代碼肯定會減少很多 – charlietfl 2014-12-19 06:27:49