开发者

Javascript, writing dynamic content to textarea

开发者 https://www.devze.com 2023-01-28 18:41 出处:网络
I am programming a bl开发者_开发技巧og in php, for the record I\'ve just started out but Im doing pretty good with this PHP but Javascript I don\'t really understand.

I am programming a bl开发者_开发技巧og in php, for the record I've just started out but Im doing pretty good with this PHP but Javascript I don't really understand.

On my blog I would like people to comment and discuss.

What I want:

Every comment has an id that is displayed.

I want to click on it and then the Javascript should place it in the textarea for leaving comments.

Thats all.


(This answer uses 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消