dom:
复制代码 代码如下:
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 do this:
复制代码 代码如下:
(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).each(function() {
// im not really even sure you need to do this for checked
// but what the heck, better safe than sorry
if (this.checked) this.setattribute('checked', 'checked');
else this.removeattribute('checked');
});
$(option, this).each(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);
