Мне кажется, что мне подходит следующее:
http://jsfiddle.net/h8AP8/1/
Вся заслуга gnarf здесь и его формы:
jQuery html () в Firefox(использует .innerHTML) игнорирует изменения DOM
Таким образом, ваш измененный код будет:
<div>
<input value='0'>
</div>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'></script>
<script>
(function($) {
var oldHTML = $.fn.html;
$.fn.formhtml = function() {
if (arguments.length) return oldHTML.apply(this,arguments);
$("input,button", this).each(function() {
this.setAttribute('value',this.value);
});
$("textarea", this).each(function() {
// updated - thanks Raja!
this.innerHTML = this.value;
});
$("input:radio,input: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);
setInterval(function() {
$('input').val(parseInt($('input').val()) + 1)
console.log('div.html(): ', $('div').formhtml())
}, 1000)
</script>