jQuery html() in Firefox (uses .innerHTML) ignores DOM chang

2016-02-19 13:33 4 1 收藏

有了下面这个jQuery html() in Firefox (uses .innerHTML) ignores DOM chang教程,不懂jQuery html() in Firefox (uses .innerHTML) ignores DOM chang的也能装懂了,赶紧get起来装逼一下吧!

【 tulaoshi.com - Web开发 】

DOM:

代码如下:

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)
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:

代码如下:

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)
(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);

来源:http://www.tulaoshi.com/n/20160219/1604615.html

延伸阅读
标签: Web开发
我们已经学习过如何来选取DOM元素,怎么创建数组,怎么创建函数,怎么把事件添加到元素,今天我们来深入地学习一下如果操纵HTML元素。通过MooTools 1.2,你可以添加新元素到一个HTML页面中,也可以删除元素,以及改变任何样式或者元素参数,这些都非常容易。 基本方法 .get(); 这个工具可以让你获取元素的属性(property)。元素的属性是...
标签: Web开发
12 设置和获取HTML、文本和值 $("selector").html() 获取html代码 $("selector").html(html) 设置html代码(替换标签中内容),html()方法不可用于XML文档 $("selector").text() 获取纯文本内容 $("selector").text(text) 设置文本内容(替换标签中内容),text()方法可以用于XML文档 $("selector").val() 获取元素的值 $("selector...
标签: Web开发
对于获取某一个元素的值,如input框,我们往往是用$('#test').val(); $('#test')这个我就不多说了,反正就是获取ID为test的这个元素。 $('#test').val(),也就是获取它的值,一般来说,凡是能够用在FORM里的元素,都可以用.val()来进行值的获取,如input,textarea,select等,都可以用.val()来获取它们的当前值 而.val('aa');则是设置该元...
标签: Web开发
IE与火狐下可以跑. //回车事件处理 $(document).keydown(function(event){ if(event.keyCode==13){ alert($('#idone').val()); //回车键盘ISBN获取 if($('#idone').val()=='isbn'){ //isbncheck(); $('#ztm').focus(); }else if($('#idone').val()=='ztm'){ $('#bltm').focus(); } if($('#idone').val()=='bltm'){ $('#ftm').fo...
标签: Web开发
什么是jQuery对象? ---就是通过jQuery包装DOM对象后产生的对象。jQuery对象是jQuery独有的,其可以使用jQuery里的方法。 比如: $("#test").html() 意思是指:获取ID为test的元素内的html代码。其中html()是 jQuery里的方法 这段代码等同于用DOM实现代码: document.getElementById("id").innerHTML; 虽然jQuery对象是包装DOM对象后产...

经验教程

122

收藏

44

精华推荐

innerHTML应用

innerHTML应用

萌萌小妈咪

使用Javascript和DOM Interfaces来处理HTML

使用Javascript和DOM Interfaces来处理HTML

补血圣药

JQuery 风格的HTML文本转义

JQuery 风格的HTML文本转义

半梦年华丶乐

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部