我在 jquery/javascript 中得到了这个简单的函数,但在 IE7、IE8 中不起作用:
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
它有什么问题吗?
最佳答案
一切看起来都很好。这是我尝试过的:( working example )
HTML:
<form>
<input type="checkbox" id="c1" value="1"> <label for="c1">test</label>
<input type="checkbox" id="c2" value="2"> <label for="c2">test</label>
<input type="checkbox" id="c3" value="4"> <label for="c3">test</label>
<input type="checkbox" id="c4" value="8"> <label for="c4">test</label>
</form>
<div id="result"></div>
Javascript:
function recalcTotalPrice(s) {
var total = 0;
s.find(':checked').each(function() {
total += parseInt(this.value, 10);
});
$('#result').html(total);
}
var selector = $('form');
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
关于jquery - IE 更改功能不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7887606/