bootstrapã®modalãã¤ã¢ãã°ãªã¼ãã³æã«å¼æ°ã渡ãããã
ãã¤ã¢ãã°ã®ã¿ã¤ãã«ã ã¨ãå
容ã®ããã¹ãã ã¨ãã
è¨å®ãã¦ãããªã¼ãã³ããããå ´åãjqueryã¨ãã§idãå¼·å¼ã«æ¸ãæãã¦ããã°
ããã®ã ããããã ã¨å¯çµåãªæãã«ãªã£ã¦ãã¾ãã®ã§ãã¤ãã³ããé§ä½¿ãã¦ããããé å¼µã£ã¦ã¿ãã
ã¾ãããã¤ã¢ãã°å´ããããªæãã§divã¿ã°ããããã¦ããã
<div class="modal hide" id="myModal"> <div class="modal-header"> <a class="close" data-dismiss="modal">Ã</a> <span id="modalHead">Modal header</span> </div> <div class="modal-body"> <span id="modalBody">One fine body</span> </div> <div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Close</a> <a href="#" class="btn btn-primary" data-dismiss="modal">Save changes</a> </div> </div>
ä¸ã®ãmodalHeaderé¨åã¨modalBodyé¨åãå¼æ°ã渡ãã¦
好ããªå½¢ã§è¨å®ã§ããããã«ãããå ´åã
ã¾ããinitializeã¤ãã³ãã¨ããã«ã¹ã¿ã ã¤ãã³ããmyModalã¨ã¬ã¡ã³ãã«
è¨å®ãã¦ãããã
initializeã¤ãã³ãã«ã¯headãbodyã¨ããããããã£ãæã¤ãªãã¸ã§ã¯ããå¼æ°ã¨ãã¦æ¸¡ãããã
<script type="text/javascript"> $(function(){ $('#myModal').on('initialize',function(event,initObj){ $('#modalHead').text(initObj.head); $('#modalBody').text(initObj.body); }); }); </script>
bootstrapã®ã¢ã¼ãã«ãã¤ã¢ãã°ã«ã¯è¡¨ç¤ºãããã¨ããé ãããã¨ãçã®ã¤ãã³ãã
è¨å®ããã¦ãããããããå¼ã°ããã¨ãã®ã³ã¼ã«ããã¯é¢æ°çãè¨å®ã§ããã
ãããå©ç¨ãã¦ã表示ãããæã«ä¸è¨ã®initializeã¤ãã³ããããªã¬ã¼ããå¦çãæ¸ãã°
å¼æ°ãè¨å®ãã¦ãã¤ã¢ãã°ãå¼ã°ããã¨ãã寸æ³ã«ãªããããã§ã¯
showã¨ããã¤ãã³ãçºçæã«ãheadText,bodyTextã¨ããidã®ããã¹ãããã¯ã¹ãã
ãã¤ã¢ãã°ã®ã¿ã¤ãã«ãå
容ãè¨å®ãã¦ãã¤ã¢ãã°ã表示ããã¦ããã
<script type="text/javascript"> $(function(){ $('#myModal').on('show',function(){ var initObj = { head: $('#headText').val(), body: $('#bodyText').val() }; $('#myModal').trigger('initialize',[initObj]); }); }); </script>
ãã®ããæ¹ã ã¨ãå¼ã³åºãå
ã®ç»é¢ã¯modalHeadãmodalBodyã¨ãã£ã
ãã¤ã¢ãã°å´ã®IDãç¥ããã«ãjavascriptã®ãã¼ã¿ã¨ãã¦ãã¤ã¢ãã°ã®ã¿ã¤ãã«ã
å
容ã渡ããã®ã§ã´ãªã´ãªæ¸ãããã¯å¤å°ã¯ççµåã«ãªãã¯ãã
ï¼å°ãªãã¨ãåããã¤ã¢ãã°ç»é¢ãããããªå ´æã§ä½¿ã£ã¦ãã¦ãIDãå¤ãã£ã¦ãã¾ã£ãæãªã©ã¯
ãã¤ã¢ãã°å´ã ãç´ãã°è¯ãã¨è¨ãå½¢ã«ãªããï¼