page reloads on changing the radio buttons

大兔子大兔子 提交于 2019-12-11 05:32:01

问题


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 :/


回答1:


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();
});


来源:https://stackoverflow.com/questions/39951921/page-reloads-on-changing-the-radio-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!