Jquery problem with IE 8
Hello i have this code that works perfect in Firefox but in IE 8 doesn't work and doesn't give me any error ?!
$(".shp_div").change(function () {
var str = "";
$("select option:selected开发者_如何转开发").each(function () {
var countprod =parseInt($("#countprod").val());
var str2 = $(this).val();
str2_array = str2.split('|');
var cost = parseInt(str2_array[0]);
var cost_extra = parseInt(str2_array[1]);
if ($("#countprod").val()>1) {
str = parseInt(((countprod-1)*cost_extra) + cost);
} else{
str = cost;
}});
$(".csq_item2").text(str);
var total =parseInt($("#subtotal").val());
var shipping=parseInt(str + total);
$(".price_total").text(shipping);
})
.change();
Since I don't have the entire picture, i am guessing you are not getting the value of the selected option, So here is the code. Its commented with "Try using this":
$(".shp_div").change(function () {
var str = "";
$("select option:selected").each(function () {
var countprod =parseInt($("#countprod").val());
// var str2 = $(this).val();
var str2 = $(this).attr("value"); // Try using this!
str2_array = str2.split('|');
var cost = parseInt(str2_array[0]);
var cost_extra = parseInt(str2_array[1]);
if ($("#countprod").val()>1) {
str = parseInt(((countprod-1)*cost_extra) + cost);
} else{
str = cost;
}});
$(".csq_item2").text(str);
var total =parseInt($("#subtotal").val());
var shipping=parseInt(str + total);
$(".price_total").text(shipping);
})
.change();
Also be aware that you need to disable quirksmode for pseudo elements to work. use DOCTYPE STRICT. For instance, if you are using php you could do something like this with an included header file:
<?php
function callback($buffer) {
return (str_replace("<!doctype html>", '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', $buffer));
}
ob_start("callback");
include('includes/header.php');
ob_end_flush();
?>
The important thing to note though, is you need to be using DOCTYPE strict! hope it helps!
You could press F12 to open the IE developer console and then run the IE8 JavaScript debugger and then you can step through and see what is happening.
精彩评论