我比較新,所以我可能沒有做到他們的權利,但我已經嘗試過。我得到的最接近的是我包含的代碼。這是一段時間的工作,但模式不會「開火」。我試圖補救,並失去了我的包容。所以在這裏。如何將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