现在我有了一个html标签:
<textarea class="form-control" comment_id={{comment_id}} id="reply_content" style="height:100%;" placeholder="comment here">This is the content</textarea>我怎样才能在这里得到html的值?我指的是字符串:“This is the content”
我试过了:
var pid= $(this).attr("comment_id");
var content =$(`textarea#reply_content[comment_id="${comment_id}"]` ).val();
console.log(content);但是work.Any的朋友不能帮上忙吗?
发布于 2021-02-25 23:37:04
在文本区域这一行,你确定你的变量{{comment_id}}前后不需要引号吗?只是问一问?
<textarea class="form-control" comment_id={{comment_id}} id="reply_content" style="height:100%;" placeholder="comment here">This is the content</textarea>要选择它,你是在一条好的道路上,你必须这样做:
var pid= $(this).attr("comment_id");
var content =$('textarea#reply_content[comment_id="'+pid+'"]').val();它应该可以工作,因为你之前在变量pid中得到了id。
另外,如果您有多个类,则应该将其更改为#reply_content而不是id,因为每个页面应该只有一个id!
发布于 2021-02-26 00:20:18
我已经解决了这个问题,我的错是我用错了名字。
https://stackoverflow.com/questions/66369458
复制相似问题