【问题标题】:Javascript, writing dynamic content to textareaJavascript,将动态内容写入文本区域
【发布时间】:2010-12-02 17:21:43
【问题描述】:

我正在用 php 编写博客,为了记录,我刚刚开始,但我用这个 PHP 做得很好,但我不太懂 Javascript。

我希望人们在我的博客上发表评论和讨论。

我想要什么:

每条评论都有一个显示的 id。

我想点击它,然后 Javascript 应该将它放在 textarea 中以离开 cmets。

就是这样。

【问题讨论】:

  • 不要打破你的泡沫,但我认为你不需要重新发明轮子。这样做很有趣,但很难继续超过某个点。有 CMS 系统。我个人推荐 WordPress。
  • 老兄,你并没有打破我的泡沫 :) 我已经使用 Wordpress 工作了多年(从事主题工作),但我正在寻找一种新的工作,所以我通过给自己一个项目来学习 php继续工作。感谢您的评论。

标签: javascript textarea onclick


【解决方案1】:

(此答案使用 jQuery。)

// getting a reference to the TEXTAREA element
var $ta = $("#new_comment textarea");

$(".comment").click(function() {
    var text = $(this).find(".text").text(); // depends of the structure
    $ta.val(text);
});

<div class="comment">
    <p class="author"> Peter </p>
    <p class="text"> Good article! </p>
</div>

【讨论】:

    猜你喜欢
    • 2011-05-19
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    相关资源
    最近更新 更多