【发布时间】:2020-05-11 06:01:03
【问题描述】:
我正在尝试通过模式调用 cmets 部分,为此我需要传递一个唯一的 id 以及 #display_comment 。当我硬编码如#display_comment1、#display_comment2 时,它可以工作。我需要知道如何将值作为变量传递。
我正在使用 dom-target 将它作为变量传递给 myData1,但它不起作用。控制台在下一行显示#display_comment & 1。
<div id="dom-target" style="display: none;">
<?php
echo htmlspecialchars($test['id']);
?>
</div>
var div = document.getElementById("dom-target");
var myData1 = div.textContent;
load_comment();
function load_comment()
{
$.ajax({
url:"fetch_comment.php",
method:"POST",
success:function(data)
{
$('#display_comment'+myData1).html(data);
}
})
}
【问题讨论】:
标签: javascript php ajax