JQuery html () in Firefox (uses. InnerHTML) ignores DOM changes_jquery

Source: Internet
Author: User
Dom:
Copy Code code as follows:

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 does this:
Copy Code code as follows:
(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). per (function () {
//Im not really even sure your need to does this for "checked"
//But what the heck, better safe than sorry
if (this.checked) this.setattribute (' checked ', ' checked ');
Else This.removeattribute (' checked ');
});
$ ("option", this). per (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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.