[英]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.