简体   繁体   English

chrome,firefox和Internet Explorer中的Ajax和html事件

[英]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>了哪个选项。

Here is an example using onchange . 这是使用onchange的示例

使用onchange作为select ,而不是onclick作为option

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery可在Internet Explorer中使用,但不能在Chrome和Firefox中使用 - jQuery works in Internet Explorer but not in Chrome and Firefox header(“Content-type:text / css”);正在使用Firefox和Chrome,但在Internet Explorer 9中它显示为“text / html” - header(“Content-type: text/css”); is working in Firefox and Chrome, but in Internet Explorer 9 it shows up as 'text/html' Chrome处于浏览器状态时,Internet Explorer不返回AJAX呼叫 - Internet Explorer not returning AJAX call while Chrome is 登录代码无法在Internet Explorer中使用,但可以在Chrome和Firefox中使用 - Sign-in code not working in Internet Explorer but yes in Chrome and Firefox 提交按钮不适用于Chrome或Firefox,但适用于Internet Explorer - The Submit Button doesn't work in Chrome or Firefox, but Works in Internet Explorer 图像和进度栏未在Internet Explorer中加载,但在Firefox,Chrome等中加载 - Image & progress bar not loading in internet explorer, but loads in firefox, chrome etc 提交按钮未出现在Firefox中,但出现在Chrome和Internet Explorer上 - Submit button does not appear in Firefox but on Chrome and Internet Explorer Magento Static 块在 Inte.net Explorer 上的位置与 Chrome 上的不同,Firefox - Magento Static Block is at a Different Place on Internet Explorer than on Chrome, Firefox Internet Explorer上的AJAX和setTimeout - AJAX and setTimeout on Internet Explorer Ajax 和 Internet Explorer - Ajax and internet explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM