[英]JavaScript HTML and PHP pop-up window
I have variable in PHP $idPost where it randomly get from database mysql. 我在PHP $ idPost中有一个变量,它从数据库mysql中随机获得。
The JavaScript below is included in the while process. while流程中包含以下JavaScript。 I hope I can get multiply var
in JavaScript too. 我希望我也可以在JavaScript中获得乘法var
。 But it doesnt seem work that way. 但这似乎并不可行。
here my javascript base onclick event: 这是我的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>
My problem is in html : 我的问题是在html中:
<textarea class="form-control" rows="2" placeholder="Type Your Comment Here" name="content" id="textarea<?php echo $idpost;?>"></textarea>
Whenever I change into id="textarea45"
(where 45 is the first idpost
) it works. 每当我更改为id="textarea45"
(其中45是第一个idpost
)时,它都可以工作。 But when I use $idpost
it dosen't work. 但是当我使用$idpost
它不起作用。
I am confused about two things. 我对两件事感到困惑。
The textarea value in JavaScript gets the last $idpost
, but in textarea id
gets the first $idpost
. JavaScript中的textarea值获取最后的$idpost
,但在textarea id
获取第一个$idpost
。
When I change from $idpost
to some variable that I auto increament, the textarea id
gets the last/biggest number, and the value in JavaScript gets the first/smallest number. 当我从$idpost
更改$idpost
我自动取消$idpost
的某个变量时,textarea id
将获得最后/最大的数字,而JavaScript中的值将获得第一个/最小的数字。
How can I use this code? 如何使用此代码?
Try the Jquery modal open function 尝试使用jQuery模式打开功能
$("#myModal").modal(); $(“#myModal”)。modal();
You can use it in the button onclick function or anywhere 您可以在按钮onclick功能或任何位置使用它
About php variables, You can use Ajax for getting the data from php. 关于php变量,您可以使用Ajax从php获取数据。 Better data format is JSON for your project 更好的数据格式是项目的JSON
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.