简体   繁体   English

如何在没有 php 和 js 节点的本地 json 文件中保存 html 字段数据

[英]How to save html field data in local json file without php and js node

I am not talking only about form, any information panel in html that I want to save in local json file for eg- There is blocks in html我说的不仅仅是表格,我想保存在本地 json 文件中的 html 中的任何信息面板,例如 - html 中有块

<div class="panel">
    <div>
    <input type="text" name="producttype" id="producttype" value="" placeholder="Product Type"/>
</div>
<div>
    <input type="text" name="productname" id="productname" value="" placeholder="Product Name"/>
</div>
<div>
    <input type="text" name="details" id="details" value="" placeholder="Details"/>
</div>
<div>
    <input type="submit" name="mysubmut" id="mysubmit" value="" />
    </div>
</div>
  

I want to save that above information in a separate local.json file, every time when I fill the above infirmation and click submit it automatically save in a local.json file without php and node js.... Is it possible??我想将上述信息保存在单独的 local.json 文件中,每次我填写上述信息并单击提交时,它都会自动保存在 local.json 文件中,没有 ZE1BFD762321E409CEE4AC0B6E8419663CZ 节点。

Thanks In Advance提前致谢

You will need some JavaScript to extract the data from the fields and change them into a json object.您将需要一些 JavaScript 从字段中提取数据并将它们更改为 json object。 You cannot do this just with HTML.您不能仅使用 HTML 来做到这一点。

If you're not using a form, I would suggest that you use the onchange event perhaps:如果您不使用表单,我建议您使用 onchange 事件:

HTML: HTML:

<input type="text" name="input_name_one"  onchange="myFunction(this.name, this.value)">
<input type="text" name=“input_name_two”  onchange="myFunction(this.name, this.value)">

JS: JS:

const obj = {};

function myFunction(key, val) {
    obj[key] = value;
}

//turn your object to a json string
const getJSONString = (obj) => {
    return JSON.stringify(obj);
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM