Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用JS获取h1标记的值?_Javascript_Jquery_Html_Wordpress - Fatal编程技术网

Javascript 如何使用JS获取h1标记的值?

Javascript 如何使用JS获取h1标记的值?,javascript,jquery,html,wordpress,Javascript,Jquery,Html,Wordpress,我有3页,2页是WordPress页面,另外1页是带有表单的自定义页面模板。这两个页面是使用wp作业管理器插件创建的。第一页有一个下拉菜单,包含作业列表。第二页是对工作的描述 现在,我想在用户单击输入按钮并将其传递到第三页并使用JS将其显示在其中一个输入文本框(Position input textbox)中之后,在第二页上获取h1标记的值 如何做到这一点 以下是 HTML: 收藏品培训师 普通JavaScript解决方案(无需框架): 使用您在普通js中给定的类,使用以下命令 var x

我有3页,2页是WordPress页面,另外1页是带有表单的自定义页面模板。这两个页面是使用wp作业管理器插件创建的。第一页有一个下拉菜单,包含作业列表。第二页是对工作的描述

现在,我想在用户单击输入按钮并将其传递到第三页并使用JS将其显示在其中一个输入文本框(Position input textbox)中之后,在第二页上获取h1标记的值

如何做到这一点

以下是

HTML:


收藏品培训师

普通JavaScript解决方案(无需框架):


使用您在普通js中给定的类,使用以下命令

var x = document.getElementsByClassName('entry-title').value;
console.log(x); //outputs collections trainer
如果您使用的是jQuery,那么它的

$('.entry-title').text

希望对您有所帮助。

如果您只想在单击按钮后获得h1值,则需要单击按钮

$.(document).ready(function(){
var header1Text ='';
 $('.application_button').onclick(function(){
   header1Text = $('h1').html();
  });
//To display it in whichever textbox you want:
$('#GivesomeIDtoYourTextBox').val(header1Text);
});

PS:您还需要在页面中包含jquery源代码。

您可以使用jquery吗?如果是这样,请在jquery中单击按钮并使用查询字符串发送到另一个页面时获取h1值

编辑

将页面中的jquery文件添加到用户jquery功能中。您需要将函数放入$(document).ready()函数中,以便将函数附加到对象中

您可以在中了解有关jquery的更多信息


$(文档).ready(函数(){
$('.application_按钮')。单击(函数(){
var headervalue=$(“.entry title”).text();
window.location=”http://homecredit.ph/testEnvironment/4537-2/?position=“+人头价值;
});
});

jQuery:获取H1值

 var gValue=jQuery("header h1.entry-title").text();
    alert(gValue);

由于需要在其他页面上获取值,因此可以通过QueryString或使用HTML5 LocalStorage发送值 示例代码:

var first_page_h1_Value=jQuery("header h1.entry-title").text();
var second_page_h1_Value=jQuery("header h1.entry-title").text();

localStorage.setItem("FirstPage", first_page_h1_Value);
localStorage.setItem("SecondPage", second_page_h1_Value);
在第三页上,您可以获得两页标题文本

 alert(localStorage.FirstPage);
 alert(localStorage.SecondPage);

如果您使用的是Jquery,那么我建议您为H1标记提供id,假设H1标记的id为“h1Title”。 HTML:


通过此操作,您将获得标题文本。

$(“.entry title”)。文本将为您提供h1值如何传递h1值?我将把该jquery放在第2页或第3页?第2页。然后从第三页的查询字符串中获取值。我将该脚本放在第二页,但当我单击按钮时,什么也没有发生,也没有重定向。您是否将脚本放在document.ready函数中?您是否包含了jquery源代码?我收到了一个警报“undefined”$('.entry title').text();你错过了圆括号。
 var gValue=jQuery("header h1.entry-title").text();
    alert(gValue);
var first_page_h1_Value=jQuery("header h1.entry-title").text();
var second_page_h1_Value=jQuery("header h1.entry-title").text();

localStorage.setItem("FirstPage", first_page_h1_Value);
localStorage.setItem("SecondPage", second_page_h1_Value);
 alert(localStorage.FirstPage);
 alert(localStorage.SecondPage);
<h1 id="h1Title">Heading here</h1>
var title = $("#h1Title").text();
//To Check Whether you are getting text or not
console.log("title :"+title);