如何使用JS获取h1标签的值? [英] How to get the value of h1 tag using JS?

查看:1528
本文介绍了如何使用JS获取h1标签的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个页面,其中2个页面是WordPress页面,另外1个页面是带有表单的自定义页面模板.这两个页面是使用wp-job manager插件创建的.第一页上有一个下拉菜单,其中包含作业列表.在第二页上是作业的说明.

现在,我想在用户单击输入按钮并将其传递到第三页并使用JS在输入文本框之一(位置输入文本框)中显示后,在第二页上获取h1标签的值./p>

该怎么做?

这是第二页的链接
第3页

HTML:

<header class="entry-header">
    <h1 class="entry-title">Collections Trainer</h1>
</header>

解决方案

香草JavaScript解决方案(无需框架):

var h1Text = document.querySelector(".entry-title").textContent;

I have 3 pages, the 2 pages are WordPress pages and the other 1 is a custom page template with a form. The 2 pages are created using wp-job manager plugin. The 1st page has had a dropdown menu and contains list of jobs. On the 2nd page is the description of a job.

Now, I want to get the value of h1 tag on the 2nd page after the user click the input button and pass it to the 3rd page and displayed it in one of the input textbox (Position input textbox) using JS.

How to do this?

Here's the link of the 2nd page
3rd page

HTML:

<header class="entry-header">
    <h1 class="entry-title">Collections Trainer</h1>
</header>

解决方案

Vanilla JavaScript solution (no framework required):

var h1Text = document.querySelector(".entry-title").textContent;

这篇关于如何使用JS获取h1标签的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆