我比较新,所以我可能没有做到他们的权利,但我已经尝试过。我得到的最接近的是我包含的代码。这是一段时间的工作,但模式不会“开火”。我试图补救,并失去了我的包容。所以在这里。如何将html文件包含到另一个文件中?
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出现在activeModal的index.html
<section>
。然后,我有让他们“火”的问题。
新人的错误,但我认为你是对的。 – doug5solas