仅在 IE 中出现 JavaScript 错误
我收到此错误,仅在 IE 中:
Object doesn't support this property or method
Line: 56
Sign: 5
Code: 0
Javascript 代码:
function recalcTotalPrice(item) {
values = $("input", item).serialize();
$.post( url,
values,
function (data,textStatus, jqXHR) {
variant_wrapper = $(item).parents(".variant");
$(".price", variant_wrapper).html(data.total_price);
56: updateProductPrice(item);
})
};
function updateProductPrice(item) {
wrapper = $(item).parents('.advertising_product');
$(".total_price", wrapper).html(sum($(".price", wrapper).map(function() {return parseFloat($(this).html())}).toArray()));
};
有人吗?
编辑 1:
下面是触发 javascript 的渲染 HTML 代码:
<li>
<label class="month" for="month">Mar</label>
<div class="week ">
<input id="386_1_10" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|10" />
<label for="386_1_10">10</label>
</div>
<div class="week ">
<input id="386_1_11" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|11" />
<label for="386_1_11">11</label>
</div>
<div class="week ">
<input id="386_1_12" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|12" />
<label for="386_1_12">12</label>
</div>
<div class="week ">
<input id="386_1_13" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|13" />
<label for="386_1_13">13</label>
</div>
</li>
<script>
$('#item_386.week_picker_wrapper').weekPicker(
{
url: '/products/100/items/386/calc_total_price'
}
);
</script>
单击复选框时,将调用 javascript。
下面是完整的 javascript 代码:
jQuery.fn.weekPicker = function(options) {
var self = this;
var week_picker = new WeekPicker(options, self);
}
jQuery.fn.weekLocker = function() {
var self = this;
var week_picker = new WeekLocker(self);
};
WeekPicker = function(options, selector) {
var url = options.url;
var yearPos = 0;
$("a.prev_year", selector).click(function() {
if (yearPos > 0) {
$(".year", selector).css("margin-left", --yearPos * -55)
$(".week_picker", selector).css("margin-left", yearPos * -185)
}
return false;
})
$("a.next_year", selector).click(function() {
if (yearPos < 2) {
$(".year", selector).css("margin-left", ++yearPos * -55)
$(".week_picker", selector).css("margin-left", yearPos * -185)
}
return false;
})
$(".disabled input[type='checkbox'], .busy input[type='checkbox'], .locked input[type='checkbox']", selector).click(function () {
return false;
})
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
function getValues(selection) {
return selection.map(function() {return $(this).html()}).toArray().join(",")
}
function recalcTotalPrice(item) {
values = $("input", item).serialize();
$.post( url,
values,
function (data,textStatus, jqXHR) {
variant_wrapper = $(item).parents(".variant");
$(".price", variant_wrapper).html(data.total_price);
updateProductPrice(item);
})
};
function updateProductPrice(item) {
var wrapper = $(item).parents('.advertising_product');
$(".total_price", wrapper).html(sum($(".price", wrapper).map(function() {return parseFloat($(this).html())}).toArray()));
};
function sum(arr) {
for(var s = 0, i = arr.length; i; s += arr[--i]);
return s;
};
recalcTotalPrice(selector);
};
编辑 2:
我摆脱了那些讨厌的错误,所以现在我“只”还有一个问题。 这个功能在 IE7、IE8 中不会触发,
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
我怀疑这是 IE 中不起作用的“变化”。我发现了这个 http://www.sitepoint.com/forums/showthread.php?626340-jQuery-change()-event-in-IE-not-triggering-properly-with-checkbox
但是我不知道如何将其实现到我的代码中。
I get this error, only in IE:
Object doesn't support this property or method
Line: 56
Sign: 5
Code: 0
Javascript code:
function recalcTotalPrice(item) {
values = $("input", item).serialize();
$.post( url,
values,
function (data,textStatus, jqXHR) {
variant_wrapper = $(item).parents(".variant");
$(".price", variant_wrapper).html(data.total_price);
56: updateProductPrice(item);
})
};
function updateProductPrice(item) {
wrapper = $(item).parents('.advertising_product');
$(".total_price", wrapper).html(sum($(".price", wrapper).map(function() {return parseFloat($(this).html())}).toArray()));
};
Anyone?
EDIT 1:
Here is the rendered HTML code that triggers the javascript:
<li>
<label class="month" for="month">Mar</label>
<div class="week ">
<input id="386_1_10" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|10" />
<label for="386_1_10">10</label>
</div>
<div class="week ">
<input id="386_1_11" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|11" />
<label for="386_1_11">11</label>
</div>
<div class="week ">
<input id="386_1_12" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|12" />
<label for="386_1_12">12</label>
</div>
<div class="week ">
<input id="386_1_13" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|13" />
<label for="386_1_13">13</label>
</div>
</li>
<script>
$('#item_386.week_picker_wrapper').weekPicker(
{
url: '/products/100/items/386/calc_total_price'
}
);
</script>
When the Checkbox is clicked the javascript is called.
Here is the full javascript code:
jQuery.fn.weekPicker = function(options) {
var self = this;
var week_picker = new WeekPicker(options, self);
}
jQuery.fn.weekLocker = function() {
var self = this;
var week_picker = new WeekLocker(self);
};
WeekPicker = function(options, selector) {
var url = options.url;
var yearPos = 0;
$("a.prev_year", selector).click(function() {
if (yearPos > 0) {
$(".year", selector).css("margin-left", --yearPos * -55)
$(".week_picker", selector).css("margin-left", yearPos * -185)
}
return false;
})
$("a.next_year", selector).click(function() {
if (yearPos < 2) {
$(".year", selector).css("margin-left", ++yearPos * -55)
$(".week_picker", selector).css("margin-left", yearPos * -185)
}
return false;
})
$(".disabled input[type='checkbox'], .busy input[type='checkbox'], .locked input[type='checkbox']", selector).click(function () {
return false;
})
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
function getValues(selection) {
return selection.map(function() {return $(this).html()}).toArray().join(",")
}
function recalcTotalPrice(item) {
values = $("input", item).serialize();
$.post( url,
values,
function (data,textStatus, jqXHR) {
variant_wrapper = $(item).parents(".variant");
$(".price", variant_wrapper).html(data.total_price);
updateProductPrice(item);
})
};
function updateProductPrice(item) {
var wrapper = $(item).parents('.advertising_product');
$(".total_price", wrapper).html(sum($(".price", wrapper).map(function() {return parseFloat($(this).html())}).toArray()));
};
function sum(arr) {
for(var s = 0, i = arr.length; i; s += arr[--i]);
return s;
};
recalcTotalPrice(selector);
};
EDIT 2:
I got rid of the nasty errors, so now I "only" have one more problem.
This function, wont fire in IE7, IE8
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
I suspect the it is the "change" that dosent work in IE. I have found this http://www.sitepoint.com/forums/showthread.php?626340-jQuery-change()-event-in-IE-not-triggering-properly-with-checkbox
But I don't know how to implement it into my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这只是你忘记了
var
!I think it's simply that you forgot
var
!