Home > Web Front-end > JS Tutorial > body text

Using userData to save form data on the client side under js_javascript skills

WBOY
Release: 2016-05-16 18:25:00
Original
1248 people have browsed it

In fact, we can use the userData behavior in Microsoft DHTML default behavior to achieve this function.

Because many netizens have asked this question, I have sorted it out and provided three examples. The following will give an introduction to the use of this behavior:

UserData Behavior (userData Behavior):

1. Description:
userData behavior writes data A UserData store to save data. userData can save data in XML format on the client computer. If you are using Windows 2000 or Windows XP, it is saved in the C:Documents and SettingsLimingUserData folder (if The operating system is not installed on the C drive, then C should be the partition where the operating system is located).

This data will always exist unless you delete it manually or set the expiration date of the data with a script.

The userData behavior provides a more dynamic and larger-capacity data structure than Cookie. The data size of the UserData storage area per page can reach 64 Kb, and each domain name can reach 640 Kb.
The userData behavior allocates UserData storage for each object through sessions. Use the save and load methods to save the UserData storage area data in the cache. Once the UserData storage area is saved, even if the IE browser is closed or refreshed, the data can be reloaded without loss the next time you enter the page.
For security reasons, the same protocol uses the same folder to save UserData storage area data.
For security reasons, a UserData store is available only in the same directory and with the same protocol used to persist the store.

Used after applying userData behavior on HTML, HEAD, TITLE and STYLE tags The save and load methods will error.
Setting the userData behavior (proposed) class on the HTML, HEAD, TITLE, or STYLE object causes an error when the save or load method is called.

Must be declared inline or in the HEAD section of the document as follows Styles:



userData behavior available for Microsoft? Win32 ?And IE 5.0 or above on Unix platform, Netscape is not supported.

2. Syntax:
HTML
Script object.style. behavior = "url('#default#userData')"
object.addBehavior ("#default#userData")
Note: The sID parameter is a unique id that can describe the tag. The ID is optional, but if present, the tag can be easily controlled in scripts.

3. Members:

expires
Set or get the expiration date of data saved using userData behavior.
Script syntax: Object ID.expires = Parameter
The parameter is a string representing the expiration date in UTC (Universal Time Coordinate, World Adjustment Time) format. This property is readable and writable and has no default value. The browser will compare this date with the current date, and if it expires, the data will automatically expire.

getAttribute()
Get the specified attribute value.

load (storage area name)
Loads the stored object data from the UserData storage area.

removeAttribute()
Removes the specified attribute value from the object.

save (storage area name)
Save object data into a UserData storage area.

setAttribute()
Set the specified attribute value.

XMLDocument
Get the XML DOM reference that stores the object data.

For specific usage, please check MSDN (http://msdn.microsoft.com)
4. Example
Example 1: Application of text box mark (Microsoft)

The code is as follows:


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]
Example 2: The application code of Checkbox tag


is as follows:

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute <script> function fnSaveInput(){ var oPersist=oPersistForm.oPersistInput; oPersist.setAttribute("sPersist",oPersist.value); //将oPersist.value存储为sPersist属性 oPersist.save("oXMLBranch"); //存储在名为oXMLBranch的UserData存储区 } function fnLoadInput(){ var oPersist=oPersistForm.oPersistInput; oPersist.load("oXMLBranch"); //载入在名为oXMLBranch的UserData存储区 oPersist.value=oPersist.getAttribute("sPersist"); //将sPersist属性赋值给oPersist.value } </script>]<script> var obj=document.all.chkbox1; obj.attachEvent('onclick',saveChecked) function saveChecked(){ obj.setAttribute("bCheckedValue",obj.checked); obj.save("oChkValue"); } window.attachEvent('onload',loadChecked) function loadChecked(){ obj.load("oChkValue"); var chk=(obj.getAttribute("bCheckedValue")=="true")?true:false; obj.checked=chk; } </script>
示例三:Select标记的应用

代码如下:


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template