【发布时间】:2017-04-06 15:59:35
【问题描述】:
我比较新,所以我可能做得不对,但我已经尝试过了。我得到的最接近的是我包含的代码。它工作了一段时间,但模态不会“触发”。我试图弥补这一点,却失去了我的包容性。就这样吧。
HTML
<!--============================================-->
<!-- End of Main Program, Modals Follow -->
<!--============================================-->
<section id="activeModal">
<!--> placeholder for every modal in this project </!-->
<!--> each modal is stored in a separate file (modals.html) </!-->
<!--> main.js builds an include with a js script, appends it here, and it executes (hopefully) </!-->
</section><!-- /activeModal -->
JS
// event listener for modals
$("button").on('click', function() {
for ( i=0; i<this.attributes.length ;i++ ) { // this - identifies the modal sought
if ( this.attributes[i].name === "data-target" ) {
var target = this.attributes[i].value; // get the modal to "fire" (data-target attribute)
};
};
modalId = "modals/"+target.substring(1, target.length)+".html"; // strip the '#' from target
$("#activeModal").empty(); // remove any previous modal information
includeHTML = '<!--#include virtual="'+modalId+'" -->'; // include via ssi (server side include)
$("#activeModal").append(includeHTML); // append the 'import' html
$(target).modal("show"); // show the modal
});
我希望大约 20 个模态中的任何一个的 html 会出现在 index.html 的 activeModal <section> 中。然后,我遇到了让它们“着火”的问题。
【问题讨论】:
标签: javascript jquery html apache