PopConfirm是一款基于bootstrap的jquery弹出层确认框插件。该jquery弹出层确认框插件兼容bootstrap2和bootstrap3。它能够使用bootstrap Popover来替代确认框功能,非常方便。
使用方法
在页面中引入jquery和bootstrap相关文件,以及jquery.popconfirm.js文件。。
< link rel = "stylesheet" href = "css/bootstrap.min.css" > < script src = "js/jquery.min.js" ></ script > < script src = "js/bootstrap.min.js" ></ script > < script src = "js/jquery.popconfirm.js" ></ script > |
HTML结构
在使用时,例如你想当用户点击一个超链接时,显示一个确认框,当用户点击确定按钮时,才去执行超链接的跳转。
< a href = "www.demo.com" id = "link" >link</ a > |
初始化插件
作为jquery插件来使用,通过popConfirm()
方法来初始化该jquery弹出层确认框插件。
$( "#link" ).popConfirm(); |
在例如有一个按钮:
< button class = "btn btn-success" data-toggle = 'confirmation' id = "button" >按钮</ button > |
点击按钮时,先弹出一个弹出层确认框,单用户点击确定按钮之后,才弹出点击按钮之后触发的消息框。
$( '#button' ).click( function () { alert( 'You clicked, and valided this button !' ); }); $( "#button" ).popConfirm(); |
配置参数
该jquery弹出层确认框插件的可用配置参数如下:
$( "[data-toggle='confirmation']" ).popConfirm({ title: "Really ?" , // The title of the confirm content: "I have warned you !" , // The message of the confirm placement: "bottom" , // The placement of the confirm (Top, Right, Bottom, Left) container: "body" , // The html container yesBtn: "Yeah" , noBtn: "Oh no !!!" }); |
你也可以通过data-confirm-*
属性来直接设置参数。
< a href = "destination.html" data-confirm-title = "My Super Title" data-confirm-content = "My Super Question" >Link</ a > |
该jquery弹出层确认框插件的github地址为:https://github.com/Ifnot/PopConfirm