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()方法提出解決方案