简体   繁体   English

页面重新加载更改单选按钮

[英]page reloads on changing the radio buttons

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. 我使用java脚本和会话存储编写了一段代码来处理这些步骤。 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: 关于radiobutton变化:

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM