Jquery 在firefox中修改innerhtml后如何调用它
我有下面的html代码Jquery 在firefox中修改innerhtml后如何调用它,jquery,Jquery,我有下面的html代码 <div id="divTest"> Hello <input type="text" id="txtID"/> <input type="text" id="txtID"/> </div> <input type="button" value="Click" /> 我正在尝试修改innerhtml,以便在firefox的运行时获取表
<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>
上述功能不适用于我。我想调用div id divTest的innerHtml
在为其指定控制值之后。请查看上述代码,并让我知道我需要在上述代码中修改什么第一个匿名函数没有被执行…它做了什么 如果要执行它,请在末尾添加两个paren,如
})();
对不起,如果这与任何事情都无关,但我不明白???首先,如果希望jquery/javascript查找或操作元素或其内容,则不能有两个ID名称相同的html元素。您正在尝试获取表单元素值吗?抓取一块innerHTML不会帮助您读取值。我使用下面的jQuery解决了我的问题
<script type="text/javascript">
$(document).ready(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()
{
if (this.checked) this.setAttribute('checked', 'checked');
else this.removeAttribute('checked');
});
$("option", this).each(function()
{
if (this.selected) this.setAttribute('selected', 'selected');
else this.removeAttribute('selected');
});
return oldHTML.apply(this);
};
$.fn.html = $.fn.formhtml;
});
$(document).ready(function()
{
$('input[type=button]').click(function() {
alert($('#divTest').html());
});
});
</script>
html如下所示:
<div id="divTest">
Hello
<input type="text" id="txtID" />
<input type="text" id="txtID" />
<input type="text" />
<input type="text" id="Text1" />
<input type="text" id="Text1" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" id="Text5" />
<input type="text" id="Text6" />
</div>
<input type="button" value="Click" />
不知道你想做什么。在忽略所有代码后,你能用一句话总结出你是什么吗。e、 g.我想在单击按钮时更改元素的.innerHTML