如何在模态内单击按钮时使用jQuery或javascript获取引导模式的数据值?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何在模态内单击按钮时使用jQuery或javascript获取引导模式的数据值?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2126字,纯文字阅读大概需要4分钟。
内容图文
我想在模态内的单击按钮上获取引导模式的数据值.
这是我的模态 –
<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.
我想获取“id”字段的模态数据值,使用jQuery或javascript在此模式中单击“是”按钮时为1234.
最佳答案:
我修改了你的小提琴:
http://jsfiddle.net/exr00e0d/
你有过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获取引导模式的数据值?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。