Implement form Element value write-back Based on JQuery

Source: Internet
Author: User

Implement form Element value write-back Based on JQuery

Form. jsp:

<% @ Page language = "java" import = "java. util. *" pageEncoding = "GB2312" %>
 Form write-back<Script type = "text/javascript" src = "jquery. form_util.js "> </script> <script type =" text/javascript ">$ (function () {var obj = {name:" zhangsi ", area:" 591 ", sex: "11", enjoy: "100011", note: "xxxxxxxxxxx"}; FormUtil. set (obj) ;}); </script>Name:
Region:--- Select ---FuzhouXiamenNingde
Gender:MaleFemale
Interest:AABBCCDDEEFF
Note:


Jquery. form_util.js:

/** Form Element writeback tool * wumingkun 2014-08-19 */var FormUtil = {// value writeback method set: function (obj) {var attr; for (attr in obj) {var element = $ ("#" + attr) [0]; var nodeName = element. nodeName; if (nodeName = "INPUT") {FormUtil. judgeType ($ (element ). attr ("type"), attr, obj [attr]);} else if (nodeName = "SELECT") {FormUtil. setSelect (attr, obj [attr]);} else if (nodeName = "TEXTAREA") {FormUtil. setValue (attr, obj [attr]) ;}}, // set the Text Field Password box in the text box to the hidden box setValue: function (key, value) {$ ("#" + key ). val (value) ;}, // set the setSelect: function (key, value) {$ ("#" + key + "option") in the drop-down box "). each (function () {if (this. value = value) {$ (this ). attr ("selected", "selected") ;}}) ;}, // set radiosetRadio: function (key, value) {$ (": radio [name = '"+ key +"'] "). attr ("checked", false); $ (": radio [value = '" + value + "']"). attr ("checked", true) ;}, // set checkboxsetCheckbox: function (key, value, isDefault) {$ (": checkbox [name = '"+ key +"'] "). attr ("checked", false); if (isDefault) {var vs = value. split (""); for (var I =. length-1; I> = 0; I --) {if (vs [I] = "1") {$ (": checkbox [name = '"+ key +"'] "). filter (": eq (" + (. length-1-i) + ")"). attr ("checked", true) ;}} else {}}, // judge judgeType: function (type, key, value) of the input type) {if (type = "text" | type = "password" | type = "hidden") {FormUtil. setValue (key, value);} else if (type = "radio") {FormUtil. setRadio (key, value);} else if (type = "checkbox") {FormUtil. setCheckbox (key, value, true );}}};



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.