大佬教程收集整理的这篇文章主要介绍了等待来自Javascript模态的“返回值”,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
>我正在使用Twitter Bootstrap’s Modals
>在某些情况下,在发生动作之前,我想用“你确定吗? (是/否)模态对话框
题 :
>内在逻辑应该是什么?
我的意思是 :
>用户点击buttonA(最终执行actionA)
>我想启动模态,等待输入(两个按钮之一 – 是/否)和/或在执行(或不)动作A之前将其传递给某些检查例程
这是我的模式的HTML代码(应该是按钮 – 不知何故 – 通过他们的onclick JavaScript例程) – 还要注意#confirmmessage将是可变的.
<div class="modal fade hide" id="confirmAlert"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">x</button> <h3 id="confirmtitle">Are you sure?</h3> </div> <div class="modal-body"> <p id="confirmmessage">Body</p> </div> <div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#" class="btn btn-danger">Yes</a> </div> </div>
只是一个想法:
>写一个函数,如checkBeforeExec(message,functionToExeC)
>将#confirmmessage设置为消息,将’href设置为Javascript:functionToExec
有意义吗?
我知道这可能听起来有点混乱 – 但我根本不知道最友善的JavaScript方式是什么?
var callBACk = function(result) { alert(result); }); // define your callBACk somewhere $('#confirmAlert').on('click','.btn,.close',function() { $(this).addClass('modal-result'); // mark which button was clicked }).on('hidden',function() { var result = $(this).find('.modal-result').filter('.btn-danger').length > 0; // attempt to filter by what you consider the "YES" button; if it was clicked,result should be true. callBACk(result); // invoke the callBACk with result });
此外,您应该同时取消和是按钮数据 – dismiss =“模态”.
以上是大佬教程为你收集整理的等待来自Javascript模态的“返回值”全部内容,希望文章能够帮你解决等待来自Javascript模态的“返回值”所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。