手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jQuery html() in Firefox (uses .innerHTML) ignores DOM changes
jQuery html() in Firefox (uses .innerHTML) ignores DOM changes
摘要:DOM:复制代码代码如下:functionDisplayTextBoxValue(){varelement=document.getElem...

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);

【jQuery html() in Firefox (uses .innerHTML) ignores DOM changes】相关文章:

javascript使用Promise对象实现异步编程

JavaScript数据结构与算法之链表

JavaScript中search()方法的使用

日历-指定日期的新闻

event.srcElement+表格应用

检测用户按键

js实现简单div拖拽功能实例

体验jQuery和AngularJS的不同点及AngularJS的迷人之处

jquery滚动特效集锦

下拉菜单的简易制作

精品推荐
分类导航