【问题标题】:Multiple submit buttons in jQuery MobilejQuery Mobile 中的多个提交按钮
【发布时间】:2015-09-09 09:42:42
【问题描述】:

我的 jQuery 移动表单中有 2 个提交按钮,我想在我的目标 php 文件中调用不同的操作。我做到了;

<form action="target.php" method="get">
    <div data-demo-html="true">
        <input type="search" placeholder="Enter keyword" name="search" id="search" value="">
    </div>
    <div data-demo-html="true">
        <fieldset data-role="controlgroup">
            <button class="ui-shadow ui-btn ui-corner-all" type="submit" name="suba">Action1</button>
            <button class="ui-shadow ui-btn ui-corner-all" type="submit" name="subb">Action2</button>
        </fieldset>
    </div>
</form>

如何区分我的目标 php 文件中的这两个提交按钮点击?

【问题讨论】:

  • 为什么不使用 id 然后点击 id 执行操作?
  • if(isset($_GET["suba"]) { /* Do part A */ }... ??
  • 看看这个链接.. 获取触发事件的源元素stackoverflow.com/questions/48239/…
  • @Pekka 你能把它作为答案发布吗?

标签: javascript php jquery jquery-mobile


【解决方案1】:

给按钮的id作为action1和action2,给foam的id作为form。

$('#action1').click(function(){
    $('#form').prop('action', 'page1.php');
});

$('#action1').click(function(){
    $('#form').prop('action', 'page2.php');
});

这应该对你有帮助。

【讨论】:

    【解决方案2】:

    你可以这样做:

    if(isset($_GET["suba"])){
    // First Button Clicked
    else if(isset($_GET["subb"])){
    // Second Button Clicked
    }
    

    【讨论】:

      【解决方案3】:

      你可以检查如下

      if(isset($_GET['suba'])){
        //button named suba is clicked
        echo "suba is cicked";
      }else if(isset($_GET['subb'])){
        //button named subb is clicked
        echo "subb is cicked";
      }
      

      【讨论】:

        【解决方案4】:

        使用isset() 函数可以检查按下了哪个按钮。

        if(isset($_GET['suba']))
            echo "suba submit button pressed";
        
        if(isset($_GET['subb']))
            echo "subb submit button pressed";
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-04-16
          • 1970-01-01
          • 1970-01-01
          • 2021-05-02
          • 2014-09-19
          • 2016-09-17
          • 2014-03-03
          相关资源
          最近更新 更多