大佬教程收集整理的这篇文章主要介绍了如何在模态内单击按钮时使用jQuery或javascript获取引导模式的数据值?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<div class="modal fade" id="mymodal" 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-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="mymodalLabel">Cancel</h4> </div> <div class="modal-body"> Are you sure you want to cancel this? </div> <div class="modal-footer"> <button type="button" id="savebutton" class="btn btn-success" >Yes</button> <button type="button" class="btn btn-danger" data-dismiss="modal">No</button> </div> </div> </div> </div>
以下是我将数据传递给模态的方式 –
更新 –
<button data-target='#mymodal' id='link' data-toggle='modal' data-id="1" class='btn btn-danger cancel_modal' style='font-size:10px;padding:2px 5px;color:white;' >Cancel 1</button> <button data-target='#mymodal' id='link' data-toggle='modal' data-id="2" class='btn btn-danger cancel_modal' style='font-size:10px;padding:2px 5px;color:white;' >Cancel 2</button> <button data-target='#mymodal' id='link' data-toggle='modal' data-id="3" class='btn btn-danger cancel_modal' style='font-size:10px;padding:2px 5px;color:white;' >Cancel 3</button> ... .. . <button data-target='#mymodal' id='link' data-toggle='modal' data-id="n" class='btn btn-danger cancel_modal' style='font-size:10px;padding:2px 5px;color:white;' >Cancel n</button>
可以从众多按钮中的任何一个调用模态,我只需要获取相关按钮的数据ID.例如 – 如果我点击“取消1”按钮,我会在点击模态中的“是”按钮后将数据ID设为1.
你有过href.而不是我采取目标(模态).
$('.cancel_modal').click(function() { //alert('called'); // we want to copy the 'id' from the button to the modal var href = $(this).data('target'); var id = $(this).data('id'); // since the value of href is what we want,so I just did it like so alert(href); // used it as the SELEctor for the modal alert(id); $(href).data('id',id); });
以上是大佬教程为你收集整理的如何在模态内单击按钮时使用jQuery或javascript获取引导模式的数据值?全部内容,希望文章能够帮你解决如何在模态内单击按钮时使用jQuery或javascript获取引导模式的数据值?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。