如何使用 jquery 替换/更改

内的标题文本?
发布于 2024-12-22 03:29:55 字数 382 浏览 0 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

枕梦 2024-12-29 03:29:55

如果你可以选择它,你就可以操纵它。

试试这个:

$(".head h3").html("your new header");

但正如其他人提到的,您可能希望 head div 有一个 id。

If you can select it, you can manipulate it.

Try this:

$(".head h3").html("your new header");

But as others mentioned, you probably want head div to have an id.

讽刺将军 2024-12-29 03:29:55

你不——不喜欢这样。
给你的标签一个id,假设它现在看起来像这样:

<h3 id="myHeader"></h3>

然后像这样设置值:

myHeader.innerText = "public offers";

you don't - not like this.
give an id to your tag , lets say it looks like this now :

<h3 id="myHeader"></h3>

then set the value like that :

myHeader.innerText = "public offers";
椒妓 2024-12-29 03:29:55
$("h3").text("context")

只需使用方法“text()”即可。

.text() 方法不能用于表单输入或脚本。设置或
获取 input 或 textarea 元素的文本值,使用 .val()
方法。要获取脚本元素的值,请使用 .html() 方法。

http://api.jquery.com/text/

$("h3").text("context")

Just use method "text()".

The .text() method cannot be used on form inputs or scripts. To set or
get the text value of input or textarea elements, use the .val()
method. To get the value of a script element, use the .html() method.

http://api.jquery.com/text/

画▽骨i 2024-12-29 03:29:55

像这样给 h3 一个 id:

<h3 id="headertag">Featured Offers</h3>

并在 javascript 函数中执行以下操作:

document.getElementById("headertag").innerHTML = "Public Offers";

Give an id to h3 like this:

<h3 id="headertag">Featured Offers</h3>

and in the javascript function do this :

document.getElementById("headertag").innerHTML = "Public Offers";
浊酒尽余欢 2024-12-29 03:29:55

试试这个,

$(".head h3").html("New header");

或者

$(".head h3").text("New header");

记住类选择器返回所有匹配的元素。

try this,

$(".head h3").html("New header");

or

$(".head h3").text("New header");

remember class selectors returns all the matching elements.

扛起拖把扫天下 2024-12-29 03:29:55

像这样的东西:

$(".head h3").html("Public offers");

Something like:

$(".head h3").html("Public offers");
久光 2024-12-29 03:29:55
jQuery(document).ready(function(){
   jQuery(".head h3").html('Public Offers');
});
jQuery(document).ready(function(){
   jQuery(".head h3").html('Public Offers');
});
披肩女神 2024-12-29 03:29:55

您可以尝试:

var headingDiv       = document.getElementById("head");
headingDiv.innerHTML = "<H3>Public Offers</H3>";

You can try:

var headingDiv       = document.getElementById("head");
headingDiv.innerHTML = "<H3>Public Offers</H3>";
风尘浪孓 2024-12-29 03:29:55

如果您使用 JQuery,则可以使用以下代码段:

onSomethingChange() {
  $("#your_element_id").text("the text you want to be appeared")
}

如果您根据某些事件更改 HTML 元素,
并且 text 方法中的字符串可以替换为另一个元素值,如下面的代码片段

onSomethingChange() {
  $("#your_element_id").text($("#your_other_element_id").val())
}

,但请记住,当您将 id 放入 HTML 元素时,这会起作用,不会用作输入之类的字段< /强>

If you're using JQuery, you could use the following snippet

onSomethingChange() {
  $("#your_element_id").text("the text you want to be appeared")
}

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

onSomethingChange() {
  $("#your_element_id").text($("#your_other_element_id").val())
}

But remember this works when you put id to your HTML elements, that will not be used as field like inputs

镜花水月 2024-12-29 03:29:55

希望对某人有所帮助:-

具有值为“className”的类属性的元素:

<h3 class="className"></h3>

您将通过类名进行引用:

const newTitle = document.querySelector(".className");

然后更改内容:

newTitle.textContent = "New Title";

Hope that help someone:-

Element with a class attribute with the value of "className":

<h3 class="className"></h3>

You will make a refernce of by the class name:

const newTitle = document.querySelector(".className");

Then change the content:

newTitle.textContent = "New Title";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文