javascript 使用 Jquery 在 HTML 中填充“p”标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11576116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Populating a "p" tag in HTML with Jquery
提问by Code Ratchet
I cant figure out the syntax for this iv browsed the net when i mention "P" it returns multiple searches regarding PHP
当我提到“P”时,我无法弄清楚这个 iv 浏览网络的语法,它返回有关 PHP 的多个搜索
What i want to do is populate a p tag text with a variable value?
我想要做的是用变量值填充 ap 标签文本?
This is my Jquery
这是我的 Jquery
$('.FOS, .MF, .CW, .OO, .LL, .CO, .TAK, .FCS, .CO').mouseover(function(e) {
var tr = $(this).closest('tr');
var Comments = tr.find('.GeneralComments').text();
if (Comments != "") {
$('div#pop-up').show();
$('p').text == Comments;
} else {
$('div#pop-up').hide();
}
return false;
});
Im trying to assign the value from Comments to the p.text but its not working?
我试图将 Comments 中的值分配给 p.text 但它不起作用?
Heres my div where the p take is situated.
这是 p take 所在的 div。
<div id="pop-up">
<h3>
Over all Notes</h3>
<p>
This is where i want the value from comments to appear?
</p>
</div>
Any help would be appreciated, thank you.
任何帮助将不胜感激,谢谢。
回答by Undefined
回答by Riz
Here is the right syntax.
这是正确的语法。
$("#pop-up > p").text(Comments);
Best way is to add ID for that p tag. and use ID to populate comments, like add id comments
to that p tag and you can use:
最好的方法是为该 p 标签添加 ID。并使用 ID 填充评论,例如将 id 添加comments
到该 p 标签,您可以使用:
$("p#comments").text(Comments);
回答by just.another.programmer
if (Comments != "") {
$('div#pop-up').show();
$('p').text(Comments);
}
== is a comparison operator, not an assignment operator.
== 是比较运算符,而不是赋值运算符。
Also in jQuery, you pass the assignment you want to make into the function as an argument.
同样在 jQuery 中,您将要进行的赋值作为参数传递到函数中。
回答by Bergi
if (Comments != "") {
$('div#pop-up')
.show()
.find('p')
.text(Comments);
}