Javascript 将ID传递给Twitter引导模型

Javascript 将ID传递给Twitter引导模型,javascript,php,jquery,html,twitter-bootstrap,Javascript,Php,Jquery,Html,Twitter Bootstrap,我试图将一个id传递给一个twitter引导模型以进行删除确认(基本的CRUD页面),但就我的一生而言,我无法让它正常工作。查看了几个仍然无法开始工作的示例。我需要获得数据id以传递给模型并附加href链接,以便他们确认将其带到适当的页面(例如:delete.php?id=5)。任何想法都将不胜感激。这是我的密码: 链接: <a href="#msgDelete" data-toggle="modal" class="open-dialog btn btn-mini btn-danger"

我试图将一个id传递给一个twitter引导模型以进行删除确认(基本的CRUD页面),但就我的一生而言,我无法让它正常工作。查看了几个仍然无法开始工作的示例。我需要获得数据id以传递给模型并附加href链接,以便他们确认将其带到适当的页面(例如:delete.php?id=5)。任何想法都将不胜感激。这是我的密码:

链接:

<a href="#msgDelete" data-toggle="modal" class="open-dialog btn btn-mini btn-danger" data-id="'.$row["id"].'">
<div id="msgDelete" class="modal hide fade" 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">Are You Sure?</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this product?  This action can not be reversed.  <br /><br /><em>Remember if you want to just hide the product from your store you can mark it as inactive.</em></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<a href="delete.php?id=" class="btn btn-danger" id="clink" >Delete Product</a>
</div>
<script type="text/javascript">

$(document).on("click", ".open-dialog", function () {
   var productId = $(this).data('id');
   console.log(productId);
   //$(".modal-body #clink").href( 'delete.php?id=' + productId );
   $("#clink").attr("href", "delete.php?idd=" + productId);
   // As pointed out in comments, 
   // it is superfluous to have to manually call the modal.
   // $('#addBookDialog').modal('show');
});

</script>

JavaScript:

<a href="#msgDelete" data-toggle="modal" class="open-dialog btn btn-mini btn-danger" data-id="'.$row["id"].'">
<div id="msgDelete" class="modal hide fade" 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">Are You Sure?</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this product?  This action can not be reversed.  <br /><br /><em>Remember if you want to just hide the product from your store you can mark it as inactive.</em></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<a href="delete.php?id=" class="btn btn-danger" id="clink" >Delete Product</a>
</div>
<script type="text/javascript">

$(document).on("click", ".open-dialog", function () {
   var productId = $(this).data('id');
   console.log(productId);
   //$(".modal-body #clink").href( 'delete.php?id=' + productId );
   $("#clink").attr("href", "delete.php?idd=" + productId);
   // As pointed out in comments, 
   // it is superfluous to have to manually call the modal.
   // $('#addBookDialog').modal('show');
});

</script>

$(文档)。在(“单击”,“打开对话框”,函数(){
var productId=$(this.data('id');
console.log(productId);
//$(“.modal body#clink”).href('delete.php?id='+productId);
$(“#clink”).attr(“href”,“delete.php?idd=“+productId”);
//正如评论中指出的那样,
//手动调用modal是多余的。
//$('#addBookDialog').modal('show');
});
在您的代码中

<a href="#msgDelete" data-toggle="modal" class="open-dialog btn btn-mini btn-danger" data-id="'.$row["id"].'">

看起来你的代码有打印错误

$("#clink").attr("href", "delete.php?idd=" + productId);
                                  -----^
应该是

$("#clink").attr("href", "delete.php?id=" + productId); 

至少显示您可以随意更改href

尝试此操作后,模型没有打开,我在href=“#msgDelete”中添加了回去,这样模型会打开,但id值仍然未通过。为什么要使用data toggle=“modal”,将其更改为data toggle=“confirmation”,然后再次将href更改为data href,就像我前面提到的那样,您不再需要href了。你想要确认而不是模态。。。只需在“点击切换确认”按钮上尝试firebug,我就可以通过那里的按钮进行调试,看看有多少javascript甚至修改了href,问题是ID从未传递过从未传递过服务器?我正在尝试将ID传递给模型。delete.php文件将与服务器交互查看我的jsfiddle-每次单击.open-dialog.Your jfiddle时,它都会在#clink上更改href。你的jfiddle正按照我想要的方式工作,但出于某种原因,我可以在我的网站上工作。我在我的控制台中得到了以下信息,你知道是什么原因造成的吗?[12:59:05.363]传递给getElementById()的空字符串@