storage form
v2.0.1
storage-form允许您将数据提交到本地存储的Web组件。
演示|进一步阅读
一般用法示例:
< script type =" module " src =" storage-form.js " > </ script >
< storage-form >
< form >
< label >
Example
< input type =" text " name =" example " value =" value " />
</ label >
< button > Submit </ button >
</ form >
</ storage-form >提交change事件而不是提交按钮的示例。光/黑模式的用例:
< script type =" module " src =" storage-form.js " > </ script >
< storage-form >
< form >
< label >
< input type =" radio " name =" theme " value =" dark " />
< span > Dark mode </ span >
</ label >
< label >
< input type =" radio " name =" theme " value =" light " />
< span > Light mode </ span >
</ label >
< label >
< input type =" radio " name =" theme " value ="" checked />
< span > Default mode </ span >
</ label >
< br />
< label >
< input type =" hidden " name =" contrast " value />
< input type =" checkbox " name =" contrast " value =" true " />
< span > High contrast </ span >
</ label >
</ form >
</ storage-form >连接到storage事件的示例:
< script type =" module " src =" storage-form.js " > </ script >
< storage-form >
< form >
< label >
Update the
< code > output </ code >
by checking the box
< input type =" hidden " name =" output " value />
< input type =" checkbox " name =" output " value =" updated " />
</ label >
</ form >
</ storage-form >
< output > </ output >
< script >
const updatePage = ( ) => {
document . querySelector ( "output" ) . innerHTML = JSON . stringify (
window . localStorage
) ;
} ;
window . addEventListener ( "storage" , updatePage ) ;
updatePage ( ) ;
</ script > 此Web组件允许您:
storage事件以将页面上的其他位置挂钩change事件的表单提交表单您有一些选择(选择其中之一):
npm install @daviddarnes/storage-form确保在项目中包括<script> (选择其中之一):
<!-- Host yourself -->
< script type =" module " src =" storage-form.js " > </ script > <!-- 3rd party CDN, not recommended for production use -->
< script
type =" module "
src =" https://www.unpkg.com/@daviddarnes/[email protected]/storage-form.js "
> </ script > <!-- 3rd party CDN, not recommended for production use -->
< script
type =" module "
src =" https://esm.sh/@daviddarnes/[email protected] "
> </ script > 感谢以下人员:
updateForm()方法提出解决方案