简体   繁体   English

隐藏jquery表单向导首页上的“后退”按钮的最佳方法是什么?

[英]What's the best way to hide the 'back' button on the first page of jquery form wizard?

We have the HTML structure used with jquery-form-wizard: 我们拥有与jquery-form-wizard一起使用的HTML结构:

<form>
  <div class='page1'>...</div>
  <div class='page2'>...</div>
  ...
  <div class='pagen'>...</div>

  <button type='reset'>...</button>
  <button type='submit'>...</button>
</form>

Now, the reset and submit button are managed by jquery-form-wizard. 现在,重置和提交按钮由jquery-form-wizard管理。 The first page has the reset button (titled "Back") disabled, and the submit button functions as "Next". 第一页禁用了重置按钮(标题为“返回”),并且提交按钮的功能为“下一步”。 When moving to page2, both buttons are enabled (the Next button is first disabled during the server-side validation, then both are enabled). 移至page2时,两个按钮均启用(在服务器端验证期间首先禁用“下一步”按钮,然后同时启用)。 This proceeds until the last page, where instead of Next we have Submit. 这一直进行到最后一页,在这里有“提交”而不是“下一步”。

Now, I would like to modify the behavior of the reset/Back button on the first page. 现在,我想修改首页上“重置/返回”按钮的行为。 Instead of disabling it, I would like to hide it. 除了禁用它,我还想隐藏它。

Can I easily achieve this via css without touching the code of jquery-form-wizard? 我可以通过CSS轻松实现这一点,而无需触摸jquery-form-wizard的代码吗? Or should I just modify it and add a "hide first back button" option? 还是应该修改它并添加“隐藏第一个后退按钮”选项?

Css would not do the trick I'm afraid (speaking out of my limited knowledge of css that is), however something like the code below would do the trick. 恐怕Css不会做到这一点(出于对CSS的有限了解),但是像下面的代码这样的东西就可以解决。 The step_shown method is used to show/hide the button appropriately (the button will be shown for just a moment when the first step is shown, but is then hidden). step_shown方法用于适当地显示/隐藏按钮(显示第一步时,该按钮仅显示一会儿,然后隐藏)。

    <script type="text/javascript">
        $(function(){
            var form = $("#demoForm");

            // hide/show the button appropriately when a step is shown
            form.bind("step_shown", function(e, data){
                if(data != undefined && !data.isFirstStep){
                    form.find(":reset").show();
                }else {
                    form.find(":reset").hide();
                }
            });

            form.formwizard({ 
                formPluginEnabled: true,
                validationEnabled: true,
                focusFirstInput : true,
                formOptions :{
                    success: function(data){$("#status").fadeTo(500,1,function(){ $(this).html("You are now registered!").fadeTo(5000, 0); })},
                    beforeSubmit: function(data){$("#data").html("data sent to the server: " + $.param(data));},
                    dataType: 'json',
                    resetForm: true
                }   
             }
            ).trigger("step_shown"); // trigger once at page load
    });
</script>

I hope this helps 我希望这有帮助

I modified jquery-form-wizard to add the page's class to the form ( patch ). 我修改了jquery-form-wizard,将页面的类添加到表单( patch )中。

After this modification, all I need to do it add this to my css: 进行此修改后,我所需要做的就是将其添加到我的CSS中:

form.formwizard-page1 input[type=reset] {
    display:none;
}

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

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