У меня есть код ниже в HTML
<div id="divTest">
Hello
<input type="text" id="txtID"/> <input type="text" id="txtID"/>
</div>
<input type="button" value="Click" />
и я пытаюсь изменить innerhtml, чтобы получить значение всех элементов управления в моей форме во время выполнения в Firefox.
см. Код JavaScript ниже:
<script type="text/javascript">
(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;
});
$(document).ready(function()
{
$('input[type=button]').click(function() {
alert($('#divTest').html());
});
});
</script>
вышеупомянутая функция не работает для меня. Я хочу вызвать innerHtml div id "divTest"
после того, как ему присвоено контрольное значение. пожалуйста, посмотрите на приведенный выше код и дайте мне знать, что мне нужно изменить в приведенном выше коде