私は比較的新しいので、私は正しいことをしていないかもしれませんが、私はそれらを試しました。私が得た最も近いものは私が含むコードです。それはしばらくの間働いていたが、モーダルは「発火しない」。私はそれを救済しようとし、私の包含を失った。だからここに行く。htmlファイルを別のファイルに含めるには?
// 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
});
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は私がactiveModal index.html
の<section>
に表示されるように、約20モーダルのいずれかのHTMLを期待しています。そして、私はそれらを「火」にする問題があります。
ルーキー間違いですが、あなたは正しいと思います。 – doug5solas