需要将变量传递给textarea按钮单击。
输入数据:
<script>
var insta = "<?php echo $instapost; ?>";
function addinsta() {
document.getElementById("txtpost").innerHTML = insta;
}
</script>
变量insta成功接收到来自php-variable的多行文本,接下来需要$instapost点击button填写<textarea>接收到的变量。
实际上我们有什么:
<button id="instabutton" onclick="addinsta()">Generate Post</button><br />
<textarea id="txtpost" name="txtpost"></textarea>
只要我没有尝试: document.getElementById("txtpost").value = insta- 也不起作用。
我究竟做错了什么?
在每行末尾插入“\”:
通过以下设计解决了该问题:
为了不在每行的末尾放置“\”,我根据 ES-2015 标准将 php 变量用反引号 `` 框起来(其中允许换行)。一切正常!
一个很好的简单解决方案是这样做:
顺便说一句,斜线被转义了,所以
</script>line不会有问题。