我的购物车中有很多 select 元素,当 select 元素更改 option 时,将监听 onclick 事件,并执行 ajax 函数 displayCart 。
<select name="price">
<option value="peryear" onclick="dispCart('y',2,1100);">1100 Dollar/year</option>
<option value="pertrimester" onclick="dispCart('t',2,300);" selected>300 Dollar/3 months</option>
<option value="permonth" onclick="dispCart('m',2,120);">120 Dollar/month</option>
</select>
这是ajax函数:
function dispCart(b,c,price){
var req1=new getXHR();
var altr=Math.random();
var url="cart.php?c="+altr+"&b="+b+"&c="+c+"&price="+price;
req1.open('GET',url,true);
req1.onreadystatechange=function(){
if(req1.readyState==4){
if(req1.status==200){
document.getElementById("cart").innerHTML=req1.responseText;
}
}
};
req1.send(null);
}
cart.php是一个 Controller ,它使用一些函数连接到数据库,更改购物车数据(例如从每月付款改为每年付款) 然后刷新购物车并显示经过更改的新购物车。
问题是这个购物车在 FF 上工作得很好,但在 IE 和 chrome 上它不执行 dispCart javascript 函数。
不知道为什么???
提前谢谢您。
最佳答案
在 IE 中,您无法绑定(bind) <option>
上的事件元素。您应该将事件绑定(bind)到 <select>
元素,然后找出选择了哪个选项。
关于php - Chrome、Firefox 和 Internet Explorer 中的 Ajax 和 html 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7519241/