【问题标题】:Make a button Default without making it Submit将按钮设为默认但不提交
【发布时间】:2014-07-29 10:34:00
【问题描述】:

我正在 FancyBox (ajax) 中打开一个页面。该页面包含一个表单。我只能通过 Ajax 提交数据,所以我没有为这个表单分配任何“动作”或“方法”。按钮类型也不是“提交”。我无法将其更改为“提交”,因为我必须在同一个花式框中加载下一页。 HTML5中有什么方法可以使按钮“默认”而不是“提交”类型?

下面是我在fancybox中打开的表格:

<form role="form" class="form-horizontal">
    <div class="form-group">
        <label for="scheduleName">Assign name</label>
        <input type="text" name="scheduleName" id="scheduleNamePopup" class="form-control" autocomplete="off">
    </div>
    <div class="form-group">
        <button type="button" id="theDefaultBtn" class="btn btn-success"><span class="glyphicon glyphicon-check"></span>Continue</button>
        <button type="button" class="btn btn-default" id="cancelFx">Cancel</button>
    </div>
</form>

【问题讨论】:

  • 你已经给它一个类,所以使用一些 jquery 你实际上可以让它可以点击来做任何你想做的事情。 -- api.jquery.com/click

标签: html forms fancybox-2


【解决方案1】:

使其提交类型并在对其影响的功能之后的 Onclick 事件中(如果有)添加 return false; 将取消提交行为 示例:

<input type="submit" onclick="yourfunction(); return false;" value="button" />

<input id="but" type="submit" value="button" />

在你的函数中

$('#but').click(function(){
    //your ajax code and stuff goes here
    return false;
    });

【讨论】:

    【解决方案2】:
    <button type="submit" onclick="submit($(this).parents('form')); return false">text</button>
    

    像这个按钮先做onclick事件,该事件绑定到按钮,触发jQuery(javascript)中的submit()函数,代码return false之后不允许按钮提交表单!

    【讨论】:

    • 纯代码答案不如附有解释为什么能解决问题的代码有用。请考虑添加细节。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 2013-09-29
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 2014-12-03
    相关资源
    最近更新 更多