javascript - Load Modal dialog by injecting HTML with JQuery -
i have following function on js file has defined html code modal dialog defined in here
i've copied html code , assigned variable on js function:
function loadmodaldialog(p1) { var modal = '<div id="mymodal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true">' + ' <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>one fine body…</p>' + ' </div>' + ' <div class="modal-footer">' + ' <button class="btn" data- dismiss="modal" aria- hidden="true"> close </button>' + ' <button class="btn btn-primary"> save changes </button>' + ' </div>' + '</div>'; }
also, have js function calls loadmodaldialog @ point not sure how inject html have on modal var dom once inside of above function can display modal dialog.
btw, want inject html through js function because change body of dialog , change dynamically according p1 value.
btw, line of code calling loadmodaldialog looks this:
<a href="" role="button" onclick=loadmodaldialog("' + p1 + '") data-toggle="modal">popup</a>
any idea how should work?
the easiest way append
modal http://api.jquery.com/append/ particular dom element(parent element).
function loadmodaldialog(p1) { var modal = .... $(parent_id).append(modal); }
updated: may want wrap modal body, header , footer within div official example ie:
<div id="mymodal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <---- need <div class="modal-content"> <---- need <div class="modal-header"> </div> <div class="modal-body"> </div> <div class="modal-footer"> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
Comments
Post a Comment