【问题标题】:Bootstrap Form Submit upon modal confirmationBootstrap 表单在模式确认后提交
【发布时间】:2018-06-12 17:30:00
【问题描述】:

目前我有一个动态生成的产品列表(基于我的数据库)。我所拥有的是一个也是动态创建的按钮,一个功能按钮。

所以功能按钮的想法是允许用户展示他/她点击过的特定产品。

因此,单击功能按钮后,将打开一个模式,允许用户选择他们希望在何处展示产品。这可以在以下屏幕截图中看到。

整个想法是,一旦用户选择了一个选项(每月特价、新品、畅销品、幻灯片),点击绿色功能按钮,这会将 productID、userID 和 featuresLocation 作为表单值提交给我的后端。

我能够以某种方式提醒我想要的值,但我意识到在第一次单击“Feature this Product”按钮时,行为就是我想要的。但是,如果我再次单击另一个产品下的“精选此产品”按钮,则警报将同时运行第一个实例和第二个实例,然后继续。以下附件说明了我的意思。

推出首个产品:

特色第二个产品:

所以这种行为只会不断叠加。目前,我的 javascript 中的内容是:

$('.featureThisProduct').click(function () {
    $('#featureModal').modal("show");
    var productID = $(this).attr("productID");
    var adminID = $(this).attr("logAdminID");
    var featureProductAs = $('#featuredAs').val();
    $('#submitFeature').on("click",function(){
        alert (adminID);
        alert (productID);
        alert (featureProductAs);
    });
});

在我的 html 中是:

使用功能按钮显示产品列表

<div class="col-xs-6 col-sm-3 col-md-3 col-lg-2 productGridListContainer">
    <div class="thumbnail productGridImageWrapper">
        <a class="view_product_info" productInfoID='.$productID.' productInfoTitle="'.$productTitle.'" logAdminID='.$adminID.'>
            <img src="'.$imgUrl.'" style="max-height:200px; max-width:150px;" class="productGridImage">
       </a>
    </div>
    <div class="productGridTitleWrapper">
        <h4 class="productGridTitle">'.$shortenedProductTitle.'</h4>
    </div>
    <div class="productGridAuthorWrapper">
        <p class="productGridAuthor">'.$shortenedProductAuthor.'<br /></p>
    </div>
    <div class="productGridButtonWrapper">
        <button class="btn btn-info btn-sm btn-block featureThisProduct" productID="'.$productID.'" logAdminID="'.$adminID.'">
            Feature this product
        </button>
    </div>
</div>

模态

<div id="featureModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">
                    Feature This Product
                </h4>
            </div>
            <div class="modal-body">
                <form id="featureForm" method="post">
                    <div class="form-group row">
                        <div class="col-xs-12 col-sm-12 col-m-12 col-lg-12">
                            <label for="featuredAs">Which area would you like to feature this product at?</label>
                            <select class="form-control" id="featuredAs">
                                <option value="special">Monthly Special</option>
                                <option value="best">Best Selling</option>
                                <option value="new">New Arrival</option>
                                <option value="slideshow">Slideshow</option>
                            </select>
                        </div>
                    </div>
                </form>    
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <button type="submit" class="btn btn-success" id="submitFeature">Feature</button>
            </div>
        </div>
    </div>
</div>

如果有人能在这方面帮助我,我将不胜感激。提前感谢您,祝您有美好的一天!

【问题讨论】:

  • 你好冷在

标签: javascript php twitter-bootstrap forms confirmation


【解决方案1】:

您将在每次功能点击中向$('#submitFeature') 添加一个事件侦听器。避免这种情况的一种方法是将其添加到$('.featureThisProduct') 侦听器之外。所以它会是这样的:

var productID, adminID, featureProductAs;

$('.featureThisProduct').click(function () {
    $('#featureModal').modal("show");
    productID = $(this).attr("productID");
    adminID = $(this).attr("logAdminID");
    featureProductAs = $('#featuredAs').val();
}

$('#submitFeature').on("click",function(){
     alert (adminID);
     alert (productID);
     alert (featureProductAs);
});

【讨论】:

  • 谢谢你,你的回答真的有效!既然您已经指出了这一点,我对它的工作原理就更加清楚了。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-22
  • 2018-09-03
  • 1970-01-01
  • 2014-11-12
  • 2022-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多