[英]JavaScript HTML and PHP pop-up window
我在PHP $ idPost中有一個變量,它從數據庫mysql中隨機獲得。
while流程中包含以下JavaScript。 我希望我也可以在JavaScript中獲得乘法var
。 但這似乎並不可行。
這是我的JavaScript基於onclick事件:
<img class="share" alt="1" src="comment.png" id="comment" onclick="myFunction()">
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("comment<?php echo $idPost;?>");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
//var idpost<?php echo $number;?> = document.getElementById("comment<?php echo $number;?>").alt;
var textarea<?php echo $idPost;?> = 'hai<?php echo $idPost;?>';
var a = "textarea";
var b = "<?php echo $idPost;?>";
var c = a+b;
document.getElementById(c).value=textarea<?php echo $idPost;?>;
// When the user clicks the button, open the modal
function myFunction() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
我的問題是在html中:
<textarea class="form-control" rows="2" placeholder="Type Your Comment Here" name="content" id="textarea<?php echo $idpost;?>"></textarea>
每當我更改為id="textarea45"
(其中45是第一個idpost
)時,它都可以工作。 但是當我使用$idpost
它不起作用。
我對兩件事感到困惑。
JavaScript中的textarea值獲取最后的$idpost
,但在textarea id
獲取第一個$idpost
。
當我從$idpost
更改$idpost
我自動取消$idpost
的某個變量時,textarea id
將獲得最后/最大的數字,而JavaScript中的值將獲得第一個/最小的數字。
如何使用此代碼?
嘗試使用jQuery模式打開功能
$(“#myModal”)。modal();
您可以在按鈕onclick功能或任何位置使用它
關於php變量,您可以使用Ajax從php獲取數據。 更好的數據格式是項目的JSON
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.