Javascript onchange(this.value,that.value)不能在ipad上运行

Javascript onchange(this.value,that.value)不能在ipad上运行,javascript,php,jquery,google-chrome,safari,Javascript,Php,Jquery,Google Chrome,Safari,我有这段代码,它在个人电脑上运行得很好,但在我的iPad上不起作用(我想它在任何手机上也不起作用)。我尝试过Safari和Chrome,但没有任何运气 HTML: <input name="Service" type="radio" value="110" onchange="update_cart(this.value, Service2.value )" /> <input name="Service" type="radio" value="111" onchange="

我有这段代码,它在个人电脑上运行得很好,但在我的iPad上不起作用(我想它在任何手机上也不起作用)。我尝试过Safari和Chrome,但没有任何运气

HTML

<input name="Service" type="radio" value="110" onchange="update_cart(this.value, Service2.value )" />
<input name="Service" type="radio" value="111" onchange="update_cart(this.value, Service2.value )" />
<input name="Service2" type="radio" value="112" onchange="update_cart(Service.value, this.value)" />
<input name="Service2" type="radio" value="113" onchange="update_cart(Service.value, this.value)" />
我知道问题出在这里,因为函数update_cart只是接收具有“this.value”的变量,而不是另一个变量,例如:当单击/点击第一个收音机时,函数接收(110,未定义),反之亦然,第二个收音机接收(未定义,112)

我的问题是:我是不是做错了什么?这不应该在手机上工作吗?有解决办法吗

编辑:现在我们有4个选项,我们的想法是能够使用您选中的新项目更新购物车,并且每次您单击另一个收音机时,它都应该更新购物车。

永远不要使用内联JS(如HTML中的onchange),除非您使用的是有意义的框架,如Angular。否则,它是有限的,丑陋的,并且可能有缺陷

您可以通过使用库或框架使其更轻、更干净。有些东西,比如说吸引人的,有棱角的,有反应的,等等,都会有很大的帮助

有关说明,请参见代码注释

//获取元素引用
var servicelems=document.querySelectorAll('[name=“Service”]');
var service2Elems=document.querySelectorAll('[name=“Service2”]');
//循环两组引用并附加“更改”侦听器
[serviceElems,service2Elems].forEach(函数集){
[]forEach.call(集合、函数(元素){
要素addEventListener(“变更”,myFn);
});
});
//单击任何元素时,都会触发此操作
函数myFn(){
//在元素集上循环,将值映射回“VAL”`
var VAL=[serviceElems,service2Elems].map(函数集){
//从该集合中查找选中的元素(如果有)
var checkedlem=[].find.call(集合,函数(元素){
返回元素检查;
});
//如果选中,则返回其值(映射到VAL)
if(checkedlem){return checkedlem.value;}
});
updateCart(VAL[0],VAL[1]);
}
var result=document.getElementById('result');
函数更新cart(radio1、radio2){
result.textContent='Service:'+radio1+'Service2:'+radio2;
}
//ES6[]的垫片。查找
if(!Array.prototype.find){
Array.prototype.find=函数(谓词){
if(this==null){
抛出新的TypeError('Array.prototype.find调用为null或未定义');
}
if(类型谓词!=='function'){
抛出新类型错误('谓词必须是函数');
}
变量列表=对象(此);
var length=list.length>>>0;
var thisArg=参数[1];
var值;
对于(变量i=0;i
Set 1
110
111
第2组
112
113
结果

那么,您希望单选按钮的行为像复选框一样吗?事件onchange不是问题所在,因此我想我不必将其更改为onblur,是的,在本例中,我希望单选按钮不同。编辑代码以获得更真实的效果situation@Raulnd我强烈反对内联事件处理程序!但是这是你的选择。你想要吗?@LShetty这似乎有效,在关闭这个之前,我会再尝试一下。
function update_cart(radio1,radio2) {
    if (Service == "" || ID_Service == "") {
        document.getElementById("Cart").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        update = new XMLHttpRequest();
    } else { // code for IE6, IE5
        update = new ActiveXObject("Microsoft.XMLHTTP");
    }
    update.onreadystatechange = function() {
        if (update.readyState == 4 && update.status == 200) {
            document.getElementById("Cart").innerHTML = update.responseText;//fills Cart div with result
        }
    }
    update.open("GET", "/new/update_cart.php?radio1=" + radio1 + "&radio2=" + radio2, true);
    update.send();
}