Firefox 31的javascript提交不工作

firefox 31 the javascript submit not working

本文关键字:工作 提交 javascript Firefox      更新时间:2023-09-26

firefox 31的javascript提交不工作问题。问题出现在产品页面,因为在选择产品之后,它没有导航到购物车页面或愿望列表页面。我在其他浏览器和火狐30上测试过,效果都很好。我也曾试图禁用其他插件,但它没有工作。我调试下面给定的代码片段和它的变量正在获得所需的值,例如,只有当用户检查了该字段时,它才进入else。如果您能提供快速的解决方案,我将不胜感激。

    echo "<input class='"button wish_btn_style'" type='"submit'" value='"Add to   
    wishlist'" onclick='"return changelocation('wishlist.php')'"><!--img   
    src='"img/wishlist_small.png'" width='"16'" height='"15'"-->";
    echo "<input class='"button cart_btn_style'" type='"submit'" value='"Add to cart'" 
    onclick='"return changelocation('cart.php')'"><!--img src='"img/cart_gray.png'" 
    width='"32'" height='"24'"-->";
function changelocation(action)
{var canigo=0;
   var x=document.getElementById('txt_quent').value;
   var status;
 if((x=="") || isNaN(x))
 {
  alert("Please enter quantity only in number");
  var canigo=1;
  return false;
    }
    if(canigo==0)
        {status=$('input:radio[name="subid"]:checked').val();
    if(isNaN(status))
    {
     alert('Please select the desired product specification');
        return false;   
    }
    else
    {
         document.getElementById('product').action=action;
        document.getElementById('product').target='_self';
        document.getElementById('product').submit();

        return true;  
    }
    }
    }

您是否有一个输入字段在您的表单命名为'action'的任何机会?

我今天在Firefox 31中遇到了一些旧代码的错误。在以前版本的Firefox中,.action解析为表单的'action'属性,但在版本31中,它已改为解析为页面上名为'action'的输入字段。

我让它再次工作通过使用jQuery:

$("#defForm").attr("action", sURL);

或者,我可以更改页面上使用的输入字段命名约定。

我很想知道Firefox行为变化的原因。

编辑:在最后一篇文章中解决了我的问题。

我也有同样的问题,但是我使用了一个输入操作,改变输入的名称对我来说是个大问题。

此脚本在以前版本的Firefox 31上可以运行。

if(ie){
    for(i=document.getElementById('miForm').attributes.length-1;i>0;i--){
        if(document.getElementById('miForm').attributes[i].name=='action'){
            document.getElementById('miForm').attributes[i].value='../views/newJSP.jsp';
            break;
        }
    }
}else document.getElementById('miForm').action='../views/newJSP.jsp';
document.getElementById('action').value='abrir';
document.getElementById('miForm').submit();

在Firefox中,if(即)不返回任何带有action名称的属性,而在以前的版本中,它是返回action属性。

我没有任何解决办法。

编辑:是个bug?

https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement.action

解决方案:

我的脚本在for循环中有一个错误。在ie中,form中属性的长度是116,动作属性的位置是114,但是在firefox中,属性的长度是5,动作的位置是0。

这是更新form.action的代码。

for(i=document.getElementById('miForm').attributes.length-1;i>=0;i--){
    if(document.getElementById('miForm').attributes[i].name=='action'){
        document.getElementById('miForm').attributes[i].value='../views/newJSP.jsp';
        break;
    }
}