如何在 jQuery 中获取 div 内的 span 标签并分配文本?
我使用以下内容,
<div id='message' style="display: none;">
<span></span>
<a href="#" class="close-notify">X</a>
</div>
现在我想找到 div 内的跨度并为其分配文本......
function Errormessage(txt) {
$("#message").fadeIn("slow");
// find the span inside the div and assign a text
$("#message a.close-notify").click(function() {
$("#message").fadeOut("slow");
});
}
I use the following ,
<div id='message' style="display: none;">
<span></span>
<a href="#" class="close-notify">X</a>
</div>
Now i want to find the span inside the div and assign a text to it...
function Errormessage(txt) {
$("#message").fadeIn("slow");
// find the span inside the div and assign a text
$("#message a.close-notify").click(function() {
$("#message").fadeOut("slow");
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个:
在你的代码中看到它!
Try this:
See it in your code!
或
或
或
or
or
or
试试这个
Try this
Vanilla JS,不带 jQuery:
适用于所有浏览器:https://caniuse.com/#search=querySelector
Vanilla JS, without jQuery:
Available in all browsers: https://caniuse.com/#search=querySelector
它将找到标签放入标签并将文本设置为跨度。
$('div').find('span').text('您的文本');
It will find the tag into tag and set text to span.
$('div').find('span').text('Your text');