onpropertychange for a textbox in Firefox?

烈酒焚心 提交于 2019-11-30 16:06:30

问题


How to handle the onpropertychange for a textbox in Firefox using JavaScript?

Below is an example:

var headerBGColorTextBox = document.getElementById('<%= tbHeaderBGColor.ClientID %>');

if (headerBGColorTextBox != null) {
  headerBGColorTextBox.pluggedElement = document.getElementById('<%= trHeaderBG.ClientID %>');
  headerBGColorTextBox.onpropertychange = function() {
    alert('function called');
    if (event.propertyName == 'style.backgroundColor' && event.srcElement.pluggedElement != null)
      alert(event.propertyName);
    event.srcElement.pluggedElement.style.backgroundColor = event.srcElement.style.backgroundColor;
  };
}

回答1:


There are two ways to mimic the onpropertychange event, Mutation events as mentioned above that should work equally across modern browsers and the "object.watch" non-standard method that will provide support for old versions of FF < 3.

See documentation on MDC.

Object.watch

Mutation events




回答2:


It appears as if the onpropertychange event is IE Specific: http://www.aptana.com/reference/html/api/HTML.event.onpropertychange.html.

However, with that said, Firefox, at least 3.0.10 does support an event called "DOMAttrModified". The following is a snippet of how it works:

document.body.addEventListener("DOMAttrModified", function () { console.log ("Args: %o", arguments); }, false);
document.body.id = "Testing";

Where console.log is the assuming the Firefox extension Firebug is installed.




回答3:


onpropertychange is non-standard. See http://msdn.microsoft.com/en-us/library/ms536956




回答4:


The following code works:

var foo = '<%= tbHeaderBGColor.ClientID %>';

function changetext() 
  {
  alert('function called');
  if (event.propertyName == 'style.backgroundColor' && event.srcElement.pluggedElement != null)
    alert(event.propertyName);

  event.srcElement.pluggedElement.style.backgroundColor = event.srcElement.style.backgroundColor;
  }

if (!!document.addEventListener)
  {
  document.getElementById(foo).addEventListener("DOMAttrModified", changetext, false);
  }
else
  {
  document.getElementById(foo).addBehavior("foo.htc");
  document.getElementById(foo).attachEvent("onpropertychange", changetext);
  }

DOM Mutation Events



来源:https://stackoverflow.com/questions/919428/onpropertychange-for-a-textbox-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!