页面会在更改单选按钮时重新加载 [英] page reloads on changing the radio buttons

查看:118
本文介绍了页面会在更改单选按钮时重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为网站上的结帐流程工作。我写了一段代码来处理这些步骤,使用java脚本和会话存储。会话存储保持当前步骤。我写了一个功能,以保持重新加载页面的同一步骤。

它可以正常工作,但在其中一个步骤中有两个单选按钮,用户可以使用它们选择付款方式。当用户选择其中一个页面时,页面重新加载但函数不会被调用。 :/这是函数:

  jQuery(document).ready(function(){
if(sessionStorage。 checkoutstepHolder> 0){
cartButtonHandler(onLoad);
}
});

问题是,为什么函数在刷新时被重新加载调用,而不是选择单选按钮导致重新加载?

也许单选按钮不会重新加载页面,也许它会做其他事情:/ / $ / $>

解决方案

我会为此使用一个单独的函数,因为您多次使用它。 pre $ jQuery(document).ready(function(){
ReloadFunction();
});

函数ReloadFunction(){
if(sessionStorage.checkoutstepHolder> 0){
cartButtonHandler(onLoad);


$ / code>

在单选按钮上更改:

  jQuery(document).on('change','#radiobuttonID',function(){
ReloadFunction();
} );


I'm working on a checkout process on a site. i wrote a piece of code to handle the steps, using java script and session storage. session storage keeps the current step. i wrote a function to stay on the same step on reloading the page.

it works fine, but there is two radio buttons on one of steps that user can choose the payment method using them. when user chooses one of them, page reloads but the function doesn't get called. :/ this is the function:

jQuery(document).ready(function() {
    if (sessionStorage.checkoutstepHolder > 0) {
        cartButtonHandler("onLoad");
    }
});

the question is, why the function gets called on reloads caused by refreshing, but not on reloads caused by choosing the radio buttons?

maybe the radio button doesn't reload the page, maybe its doing something else :/

解决方案

I would use a seperate function for this, because you use it on multiple occasions.

jQuery(document).ready(function() {
    ReloadFunction();
});

function ReloadFunction() {
    if (sessionStorage.checkoutstepHolder > 0) {
        cartButtonHandler("onLoad");
    }
}

On radiobutton change:

jQuery(document).on('change', '#radiobuttonID', function(){
    ReloadFunction();
});

这篇关于页面会在更改单选按钮时重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆