如何使用 jquery 替换/更改内的标题文本?
如何使用 javascript 更改/替换
文本:“Featured Offers”以表示“Public Offers”?
</div> <!-- FEATURED OFFERS -->
<div class="panel">
<div class="head">
<h3>Featured Offers</h3>
</div>
<div class="body">
<table>
<thead>
<tr>
How do I change/replace the <h3>
text: "Featured Offers" using javascript to say "Public Offers" instead?
</div> <!-- FEATURED OFFERS -->
<div class="panel">
<div class="head">
<h3>Featured Offers</h3>
</div>
<div class="body">
<table>
<thead>
<tr>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果你可以选择它,你就可以操纵它。
试试这个:
但正如其他人提到的,您可能希望
head
div 有一个 id。If you can select it, you can manipulate it.
Try this:
But as others mentioned, you probably want
head
div to have an id.你不——不喜欢这样。
给你的标签一个id,假设它现在看起来像这样:
然后像这样设置值:
you don't - not like this.
give an id to your tag , lets say it looks like this now :
then set the value like that :
只需使用方法“text()”即可。
http://api.jquery.com/text/
Just use method "text()".
http://api.jquery.com/text/
像这样给 h3 一个 id:
并在 javascript 函数中执行以下操作:
Give an id to h3 like this:
and in the javascript function do this :
试试这个,
或者
记住类选择器返回所有匹配的元素。
try this,
or
remember class selectors returns all the matching elements.
像这样的东西:
Something like:
您可以尝试:
You can try:
如果您使用 JQuery,则可以使用以下代码段:
如果您根据某些事件更改 HTML 元素,
并且 text 方法中的字符串可以替换为另一个元素值,如下面的代码片段
,但请记住,当您将 id 放入 HTML 元素时,这会起作用,不会用作输入之类的字段< /强>
If you're using JQuery, you could use the following snippet
This is if you change your HTML element depending on some event,
and the string inside text method could be replaced with another element value like the following snippet
But remember this works when you put id to your HTML elements, that will not be used as field like inputs
希望对某人有所帮助:-
具有值为“className”的类属性的元素:
您将通过类名进行引用:
然后更改内容:
Hope that help someone:-
Element with a class attribute with the value of "className":
You will make a refernce of by the class name:
Then change the content: