javascript - jquery generate modal box -
i display modal box. possible? have code below showing how generate textboxes etc.
$(document).ready(function(){ var counter = 1; $(".thing").click(function generatemodal () { var newmodal = $(document.createelement('div')) .attr("id", 'mymodal' + counter).attr("class", 'modal hide fade').attr("tabindex", '-1').attr("role", 'dialog').attr("aria-labelledby", 'mymodallabel').attr("aria-hidden", 'true'); newmodal.after().html('<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="mymodallabel">modal header</h3></div><div class="modal-body"><p><img src="img/werk/logo.jpg" class="pull-right" alt=""><p>one fine body…</p></div>'); //excecute new modal?// counter++; }); });
this solution based on http://www.webdesignerdepot.com/2012/04/techniques-for-creating-modal-windows/. create modal dialog div-"layer" covering whole screen used.
<!doctype html> <html> <head> <title>modal window</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script type="text/javascript"> var newmodal; function executemodal() { $("#blind").attr("z-index", 9999).show(); $("#modaldivcontainer").append(newmodal).show(); } function closemodal(count) { $("#modaldivcontainer").hide(); $("#mymodal" + count).remove(); $("#blind").attr("z-index", 0).hide(); } $(document).ready(function() { var counter = 1; $(".thing").click(function generatemodal() { newmodal = $(document.createelement('div')) .attr("id", 'mymodal' + counter).attr("class", 'modal hide fade').attr("tabindex", '-1').attr("role", 'dialog').attr("aria-labelledby", 'mymodallabel').attr("aria-hidden", 'true'); newmodal.after().html('<div class="modal-header"><button onclick="closemodal(' + counter + ')" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="mymodallabel">modal header</h3></div><div class="modal-body"><p><img src="img/werk/logo.jpg" class="pull-right" alt=""><p>one fine body…</p></div>'); executemodal(); counter++; }); }); </script> <style type="text/css"> .blind { z-index:0; position:absolute; top:0; left:0; width:100%; height:100%; display: none; background-color:#555; } .modaldivcontainer { z-index: 10000; position:absolute; top: 50%; left: 50%; width:400px; height:300px; margin-left:-200px; margin-top:-150px; display: none; background-color:#ffffff; } </style> </head> <body> <div class="blind" id="blind"></div> <div class="modaldivcontainer" id="modaldivcontainer"></div> <button class="thing">thing</button> </body> </html>
Comments
Post a Comment