[英]Ajax and html events in chrome, firefox and Internet Explorer
I have many select elements in a cart, when a select element changes option , a onclick event will be listened to , and an ajax function displayCart will execute. 我的购物车中有很多选择元素,当选择元素更改选项时,将监听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>
this is the ajax function: 这是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);
}
The cart.php is a controller , which connects using some functions to connect to the database , change the cart data ( for example from paiement per month to paiement per year) then refreshes the cart and displays the new cart with the changes . cart.php是一个控制器,该控制器使用某些功能进行连接以连接到数据库,更改购物车数据(例如,从每月的paiement更改为每年的paiement),然后刷新购物车并显示具有更改的新购物车。
the problem is that this cart works great with FF, but with IE and chrome it doesn't execute the dispCart javascript function. 问题在于此购物车可与FF完美搭配使用,但对于IE和chrome,它无法执行dispCart javascript函数。
I don't know why??? 我不知道为什么?
thank you in advance. 先感谢您。
In IE you cannot bind events on the <option>
element. 在IE中,您不能在
<option>
元素上绑定事件。 You should bind the event to the <select>
element and then find out which option is selected. 您应该将事件绑定到
<select>
元素,然后找出<select>
了哪个选项。
使用onchange
作为select
,而不是onclick
作为option
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.