JQuery为什么不更改IE中的选择选项? [英] Why doesn't JQuery change select options in IE?
本文介绍了JQuery为什么不更改IE中的选择选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在尝试使一个保管箱更改为另一个.我们有这段代码,可以在Firefox,Safari和chrome上正常运行.但是在IE 8+中,更改第一个下拉列表与第二个下拉列表没有区别.为了使它在IE中工作,我们需要更改什么?谢谢,
We're trying to make one drop box change another. We have this code which works fine on Firefox, safari and chrome. But in IE 8+ changing the first dropdown makes no difference to the second. What do we have to change to make it work in IE ? Thanks,
我们有这个jquery:
We have this jquery:
//set up the global variable maxChecks which stops donor ticking too many boxes
var maxChecks
var checkCount=0
var boxeschecked = 0
//now change the drop down
jQuery.noConflict();
jQuery(document).ready(function($) {
$(function() {
$("#json-one").change(function() {
if ($(this).val() >= "1" ) {
$("#hide1").slideDown("fast"); //Slide Down Effect
}
var $dropdown = $(this);
var key = $dropdown.val();
var vals = [];
switch(key) {
case '1': document.getElementById("t3").innerHTML ="<option value=2>£2.50 per month</option>, <option value=3>£30 per year</option>, <option value=1>A single donation of £30</option>"; maxChecks=1; boxeschecked=0; checkCount=0; document.getElementById("nsdiv").innerHTML =""; for (var i = 0; i < 1 ; i++) {document.getElementById("nsdiv").innerHTML +='<input type="hidden" name="childid[]" value="newchild" checked>';} break;
case '2': document.getElementById("t3").innerHTML ="<option value=5>£5 per month</option>, <option value=4>£60 per year</option>, <option value=22>A single donation of £60</option>"; maxChecks=2; boxeschecked=0; checkCount=0; document.getElementById("nsdiv").innerHTML =""; for (var i = 0; i < 2 ; i++) {document.getElementById("nsdiv").innerHTML +='<input type="hidden" name="childid[]" value="newchild" checked>';} break;
case 'base': vals = ['-'];
}
$jsontwo.empty();
});
});
});
这是html:
<select id="json-one" name="json-one">
<option selected value="base">Please select</option>
<option value="1">1 child</option>
<option value="2">2 children</option>
</select>
<!-- this select box will be hidden at first -->
<div style="display:none;" id="hide1">
By donating <select id="t3" name="t3"><option>-</option></select>
</div>
推荐答案
以下内容似乎在IE中起作用:
The below appears to be working in IE:
//set up the global variable maxChecks which stops donor ticking too many boxes
var maxChecks;
var checkCount=0;
var boxeschecked = 0;
//now change the drop down
jQuery.noConflict();
jQuery(document).ready(function($) {
$(function() {
$("#json-one").change(function() {
if ($(this).val() >= "1" ) {
$("#hide1").slideDown("fast"); //Slide Down Effect
}
var key = $(this).val();
var vals = [];
switch(key) {
case "1":
$("#t3").html('<option value=2>£2.50 per month</option> <option value=3>£30 per year</option> <option value=1>A single donation of £30</option>');
maxChecks=1;
boxeschecked=0;
checkCount=0;
$("#nsdiv").html('');
for (var i = 0; i < 1 ; i++) {
$("#nsdiv").append('<input type="hidden" name="childid[]" value="newchild" checked>');
}
break;
case "2":
$("#t3").html('<option value=5>£5 per month</option> <option value=4>£60 per year</option> <option value=22>A single donation of £60</option>');
maxChecks=2;
boxeschecked=0;
checkCount=0;
$("#nsdiv").html('');
for (var i = 0; i < 2 ; i++) {
$("#nsdiv").append('<input type="hidden" name="childid[]" value="newchild" checked>');
}
break;
case 'base':
vals = ['-'];
break;
}
});
});
});
请参见此处的示例: http://jsfiddle.net/m6A8z/
这篇关于JQuery为什么不更改IE中的选择选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文