Javascript 以html格式将所选数据从一个页面传递到另一个页面

Javascript 以html格式将所选数据从一个页面传递到另一个页面,javascript,html,Javascript,Html,我正在使用表单将数据从一个页面传递到另一个页面。如果我单击应用按钮将转到另一个页面,我希望在下一个页面中显示相应的职业头衔(即Java开发人员)。我尝试在javascript的帮助下实现这一点 career.html: <form action="job portal.html" method="get" target="_blank"> <div class="section-header text-center wow zoo

我正在使用表单将数据从一个页面传递到另一个页面。如果我单击应用按钮将转到另一个页面,我希望在下一个页面中显示相应的职业头衔(即Java开发人员)。我尝试在javascript的帮助下实现这一点

career.html:

    <form action="job portal.html" method="get" target="_blank">
                    <div class="section-header text-center wow zoomIn">
                        <h2>Current Oppournities</h2>

                    </div><br /><br />

                    <div class="row">


                        <div class="col-lg-6">
                            <div class="box wow fadeInLeft">

                                <h4 class="title" id="career-title" name="career-title"><a href=""><i class="fa fa-java"></i>&nbsp;<b>Java Developer</b></a></h4>
                                <hr />
                                <div class="carrer-opt">
                                    <h5 name="test">Software Developer</h5>

                                    <p>

                                        Should have join immediate joiner .
                                    </p>

                                </div>
                                <div class="col-lg-3 cta-btn-container">
                                    <input type="submit" id="apply"  value="Apply Now" onClick="testJS()" />
                                </div>
                            </div>
                        </div>

</form>

当前机会



软件开发人员 应该加入直接加入者。

js:

<script src="js/main.js"></script>
    <script>
        function testJS() {
            var b = document.getElementById('career-title').value,
                url = 'job portal.html?career-title=' + encodeURIComponent(b);

            document.location.href = url;
        }
    </script>

函数testJS(){
var b=document.getElementById('career-title')。值,
url='job portal.html?职业头衔='+encodeURIComponent(b);
document.location.href=url;
}
job portal.html:

 <h1 id="here" style="color:black"></h1>

js:


window.onload=函数(){
var url=document.location.href,
params=url.split('?')[1]。split('&'),
数据={},tmp;
对于(变量i=0,l=params.length;i

如何实现这一点。任何人都请帮助。

对于此类问题,您需要使用HTML5本地存储。 这是你问题的解决方案

<script>
    function testJS() {
        var b = document.getElementById('career-title').value;
        var titleText = localStorage.setItem('title', b);
        var url = 'job portal.html';

        document.location.href = url;
    }
</script>

函数testJS(){
var b=document.getElementById('career-title')。值;
var titleText=localStorage.setItem('title',b);
var url='job portal.html';
document.location.href=url;
}
设置标题值后,通过引用prtal.html脚本中的id“title”获取值,并为元素设置值

<script>
    window.onload = function () {
        var valueText = localStorage.getItem('title');
        document.getElementById('here').innerHTML = valueText;
    }
</script>

window.onload=函数(){
var valueText=localStorage.getItem('title');
document.getElementById('here').innerHTML=valueText;
}

选中此项-但我想根据行
document.getElementById('career-title')中所选的值显示标题。值
返回
未定义
因此更改
文档。querySelector('#career-title b')).innerHTML
以获取职业标题。它也不会返回任何值。选中此项-它在job portal.html页面中显示未定义。它的工作是使用小更改而不是document.getElementById('career-title')。值更改为document.querySelector('#职业标题b')).innerHTMLIt只在localstorage中存储一个值。如何设置和获取多个值对于多个值,您可以创建对象,然后在任何需要使用的位置检索该对象。
<script>
    window.onload = function () {
        var valueText = localStorage.getItem('title');
        document.getElementById('here').innerHTML = valueText;
    }
</script>