Implement form Element value write-back Based on JQuery and jquery implement form Element
Form. jsp:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "GB2312" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
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 );}}};
Can I use jquery to change the name value of an element in a form?
Just change it. Try
$ ("# Yourfromid"). submit (function (){
$ ("# Inputid"). attr ("name", "new_name ");
});
How does jquery clear values in form elements?
$ ("Input"). val ("")