Dom:
Copy Code code as follows:
function Displaytextboxvalue () {
var element = document.getElementById (' textbox ');
Set the attribute on the DOM Element by Hand-will update the InnerHTML
Element.setattribute (' value ', element.value);
Alert (document.getElementById ("container"). InnerHTML);
return false;
}
JQuery plugin that makes formhtml () automatically does this:
Copy Code code as follows:
(function ($) {
var oldhtml = $.fn.html;
$.fn.formhtml = function () {
if (arguments.length) return oldhtml.apply (this,arguments);
$ ("Input,textarea,button", this). each (function () {
This.setattribute (' value ', this.value);
});
$ (": Radio,:checkbox", this). per (function () {
//Im not really even sure your need to does this for "checked"
//But what the heck, better safe than sorry
if (this.checked) this.setattribute (' checked ', ' checked ');
Else This.removeattribute (' checked ');
});
$ ("option", this). per (function () {
//also not sure, but, better safe ...
if (this.selected) this.setattribute (' Selected ', ' selected ');
Else This.removeattribute (' selected ');
});
Return oldhtml.apply (this);
};
//optional to override real. HTML () If you want
//$.fn.html = $.fn.formhtml;
}) (JQuery);