Javascript 如果用户通过引导对话框确认,则重定向到相应的链接

Javascript 如果用户通过引导对话框确认,则重定向到相应的链接,javascript,html,css,twitter-bootstrap,redirect,Javascript,Html,Css,Twitter Bootstrap,Redirect,首先,javascript确认不是我在这里想要的。请阅读全文。 i、 e.将onClick attr放在每个链接上,并向其传递一个函数,该函数通过警告一个正常的系统对话框来确认用户,这不是我想要的 我使用了引导对话框,而不是系统提供的常规对话框 以下是用于不同项目的几个删除按钮 <a href="www.mysite.com/product/1" data-target="#myModal" data-toggle="modal"><i class="icon-remove"

首先,javascript确认不是我在这里想要的。请阅读全文。 i、 e.将onClick attr放在每个链接上,并向其传递一个函数,该函数通过警告一个正常的系统对话框来确认用户,这不是我想要的

我使用了引导对话框,而不是系统提供的常规对话框

以下是用于不同项目的几个删除按钮

<a href="www.mysite.com/product/1" data-target="#myModal"  data-toggle="modal"><i class="icon-remove"></i> Delete</a>
<a href="www.mysite.com/product/2" data-target="#myModal"  data-toggle="modal"><i class="icon-remove"></i> Delete</a>
<a href="www.mysite.com/product/3" data-target="#myModal"  data-toggle="modal"><i class="icon-remove"></i> Delete</a>
下面是使用引导显示模式的标记

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Confirm Delete ?</h3>
  </div>
<div class="modal-body">
  <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to Delete the Category and all its associated Properties?</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
  </div>
</div>

对话框显示正确,但在按下对话框中的“删除”按钮后,我无法重定向到与上述链接对应的页面,模式只是显示出来而没有重定向

在引导标记中添加数据属性并向服务器发送ajax请求,这样就可以删除项目而无需动态刷新页面

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Confirm Delete ?</h3>
  </div>
<div class="modal-body">
  <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to Delete the Category and all its associated Properties?</p>
  </div>
  <div class="modal-footer">
    <a class="btn" data-dismiss="modal" aria-hidden="true">Cancel</a>
    <a class="btn btn-danger" data-action="delete-item" data-item="XXX" data-dismiss="modal">Delete</a>
  </div>
</div>
现在,您必须绑定它,通过该链接的单击事件,可以轻松地完成以下操作-

$(".remove-item").bind( "click", function() {
   show_dialog_for($this.prop("data-item"));
});
对于以下链接,我添加了一个类属性remove item和带有XXX的数据项

<a href="www.mysite.com/product/1" class="remove-item" data-item="XXX" data-target="#myModal"  data-toggle="modal"><i class="icon-remove"></i> Delete</a>

希望这能对您有所帮助。

在引导标记中添加数据属性并向服务器发送ajax请求,这样就可以在不刷新页面的情况下删除项目

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Confirm Delete ?</h3>
  </div>
<div class="modal-body">
  <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to Delete the Category and all its associated Properties?</p>
  </div>
  <div class="modal-footer">
    <a class="btn" data-dismiss="modal" aria-hidden="true">Cancel</a>
    <a class="btn btn-danger" data-action="delete-item" data-item="XXX" data-dismiss="modal">Delete</a>
  </div>
</div>
现在,您必须绑定它,通过该链接的单击事件,可以轻松地完成以下操作-

$(".remove-item").bind( "click", function() {
   show_dialog_for($this.prop("data-item"));
});
对于以下链接,我添加了一个类属性remove item和带有XXX的数据项

<a href="www.mysite.com/product/1" class="remove-item" data-item="XXX" data-target="#myModal"  data-toggle="modal"><i class="icon-remove"></i> Delete</a>
希望这将对您有所帮助。

只需将类删除项添加到您的链接中,并将此脚本添加到您的页面中即可。又好又干净

<script>
$(function () {
  $('a.remove-item').click(function () {
    var url = this.href;
    $('#myModal .btn-danger').click(function () {
      window.location.href = url;
    });
  });
});
</script>
只需将类删除项添加到链接中,并将此脚本添加到页面中。又好又干净

<script>
$(function () {
  $('a.remove-item').click(function () {
    var url = this.href;
    $('#myModal .btn-danger').click(function () {
      window.location.href = url;
    });
  });
});
</script>
您需要将此javascript代码添加到页面:

    $(".delBtn").click(function() {
        $("#delConfirmBtn").attr("href", $(this).attr("href"));
        $("#delConfirm").modal('toggle');
        return false;
    });
这是页面链接:

<a href="del_products.html?idproduct=1" class="delBtn btn btn-default">Delete</a>
这是模态链接:

<a href="#" id="delConfirmBtn" class="btn btn-danger">Delete</a>
这是模态代码:

  <!-- Modal -->
  <div class="modal fade" id="delConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Delete product</h4>
        </div>
        <div class="modal-body">
            <p>Lorem ipsum.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <a href="#" id="delConfirmBtn" class="btn btn-danger"><i class="icon-trash"></i> Delete</a>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
你可以在屏幕上看到你的代码

您需要将此javascript代码添加到页面:

    $(".delBtn").click(function() {
        $("#delConfirmBtn").attr("href", $(this).attr("href"));
        $("#delConfirm").modal('toggle');
        return false;
    });
这是页面链接:

<a href="del_products.html?idproduct=1" class="delBtn btn btn-default">Delete</a>
这是模态链接:

<a href="#" id="delConfirmBtn" class="btn btn-danger">Delete</a>
这是模态代码:

  <!-- Modal -->
  <div class="modal fade" id="delConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Delete product</h4>
        </div>
        <div class="modal-body">
            <p>Lorem ipsum.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <a href="#" id="delConfirmBtn" class="btn btn-danger"><i class="icon-trash"></i> Delete</a>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->

您可以在omg上看到您的代码,这是一个非常简单的解决方案。那次为什么我没有想到……:天哪,这么简单的解决方案。那次为什么我没有想到……: