简体   繁体   English

如何从一种HTML表单获取“ make”价值?

[英]How to get “make” value from one HTML form to another?

I'm having an issue sharing a value between my HTML forms. 我在HTML表单之间共享值时遇到问题。 I'm a beginner so this is probably a very easy fix. 我是一个初学者,所以这可能是一个非常简单的修复。

Newvehicle.html: Newvehicle.html:

<div class="input-group">
    <input class="form-control" id="inputMake" type="text" placeholder="Make..." style="width: 150px;"/>
</div>

Item1.html: Item1.html:

<label>Make: </label><li onclick="getMake()"></li></br>

Newvehicle.js: Newvehicle.js:

function getMake(){
    var make = document.getElementById("inputMake").value;
}

I would like the value inputted into the text field on Newvehicle.html to display as a list item on Item1.html. 我希望输入到Newvehicle.html的文本字段中的值在Item1.html上显示为列表项。 Can someone please advise? 有人可以请教吗?

What you could do is, to save the value in localStorage and retrive it in the secound file. 您可以做的是将值保存在localStorage中,然后在secound文件中检索它。

A possible HTML solution would be: 可能的HTML解决方案是:

Newvehicle.html: Newvehicle.html:

<div class="input-group">
   <input class="form-control" id="inputMake" type="text" placeholder="Make..." style="width: 150px;" onkeyup="localStorage.value1 = this.value" />
</div>

Item1.html: Item1.html:

<label>Make: </label><li id='entry_1'></li></br>
<script type="text/javascript">
            document.getElementById('entry_1').innerHTML = localStorage.value1;
</script>

Newvehicle.js: Newvehicle.js:

not required for that, but nice to have the whole logic in a seperate JS file 不需要这样做,但是很高兴将整个逻辑放在单独的JS文件中

Explanation: 说明:

the onkeyup event fires up each time the usert releases a key on the keyboard, so with each firing we create/replace the value1 in localStorage. 每次用户释放键盘上的键时都会触发onkeyup事件,因此每次触发时,我们都会在localStorage中创建/替换value1。

right after the list element will a javasript code be executed that reads the value from localStorage in your case value1 and replaces the innerHTML. 在list元素之后,将立即执行javasript代码,该代码从您的案例value1中的localStorage读取值并替换innerHTML。

keep in mid that this only works if you work on the same domain.Localstorage keeps the data until you clear the localstorage whit localStorage.clear() 请记住,这仅在您在同一域上工作时才有效。Localstorage会保留数据,直到您清除localStorage.clear()的localstorage。

alternatively you can use sessionStorage instead of localStorage tho keep the data only for one browsing session. 或者,您可以使用sessionStorage代替localStorage或仅保留一个浏览会话的数据。

See: Webstorage on W3C Schools 请参阅: W3C学校上的Webstorage

Keep on going and soon you will master the Javasript language. 继续前进,很快您将掌握Javasript语言。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从一个html页面获取单选按钮的价值? - How to get value of radio buttons from one html page to another? 如何传输一个html文件的表单值,并使其作为另一个文件中的值? - How do I transfer the form values of one html file and make it as a value in another? 将值从一个html表单移动到另一个html表单,因此一个表单从其自身提交值,而另一表单从 - move value from one html form to another, so one form submits values from itself and another form 如何使用一个HTML文件中的表格中的值以另一HTML文件中的形式使用 - How to use a value from a table in one html file in a form that is in another html file 如何从一个表单获取价值并使用javascript发布到另一个表单? - How to get value from one form and post to the another form using javascript? 如何从一个HTML页面重定向到另一HTML - How to make redirect from one html page to another html JQuery和HTML:如何使用echo $ _POST将数据从一个表单获取到另一个表单 - JQuery & HTML: How to use echo $_POST to get data from one form to another 如何从一个 html 表单中获取数据并将其显示在另一个表单上? - How can I get a data from one html form and display it on another? 如何将某些HTML从一个页面转换为另一页面的表单? - How can I get certain HTML from one page into a form onto another? 如何从一个组件到另一个组件获取价值? - How to get value from one component to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM