モーダルを開くボタンがありますが問題なく動作しますが、ボタンからモーダル内のフィールドにデータを渡したいと思っています。モーダルポップアップにデータを渡す
HTML
<input type=button value='Add Background' id='myBtn2' data-toggle="modal" data-id="@book.Id" title="Add this item" class="open-AddBookDialog">
<div id="myModal2" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close2">×</span>
<form action="includes/back.php" method="post" enctype="multipart/form-data">
<center>
<h2><b>Background Information</b></h2>
<INPUT TYPE="text" NAME="army_id" id="army_id" size="auto" value="">
<font>Background Title: </font>
<INPUT TYPE="text" NAME="back_name" size="auto" value="">
<font>Background Info: </font>
<INPUT TYPE="textarea" NAME="commander" size="auto" value="">
<input type="text" name="bookId" id="bookId" value=""/>
<font>
<b>STOP!</b><br>
Please check your information before pressing the submit button below. Looking over your information now will make sure editing later won't be necessary. Thank you.<BR>
<input type="hidden" name="FormSubmit" value="Yes">
<INPUT TYPE="submit" name="submit" value="Submit Regiment"> <INPUT TYPE="reset" value="Reset Fields">
JS
var modal2 = document.getElementById('myModal2');
// Get the button that opens the modal
var btn2 = document.getElementById("myBtn2");
// Get the <span> element that closes the modal
var span2 = document.getElementsByClassName("close2")[0];
// When the user clicks the button, open the modal
btn2.onclick = function() {
modal2.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span2.onclick = function() {
modal2.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal2) {
modal2.style.display = "none";
}
}
私は、誰かがそれを行う方法を私に助言することができ期待していますか?
スニペットを動作させることはできますか?モーダルに何を渡したいですか? –
あなたがあなたの ''タグを閉じてしまったのかどうかわかりません。すべてのdivの開閉が一致し、正しく閉じた場合 –
私のコードにを追加するのを忘れました。私はスニペットを追加したと思った。 – Foster