jQuery / Javascript - 如何在更改按钮值时触发事件?

时间:2022-11-05 15:24:02

I am working on a plugin for jQuery that will essentially style certain elements. Like jqTransform I could just replace the element but I chose to position the real element off screen and make a new element thats styled. This allows triggering the actual events of the real element. Also, if an onclick handler or onchange handler for a textbox is there, jqTransform will not include that whereas this way, it will include it.

我正在为jQuery创建一个插件,它基本上会为某些元素设置样式。像jqTransform我可以只替换元素,但我选择将真实元素放在屏幕上并制作一个新的元素。这允许触发真实元素的实际事件。此外,如果文本框的onclick处理程序或onchange处理程序存在,jqTransform将不包括,而这样,它将包括它。

Here is my problem. Say a user has a button. Later on in the app the user decides to change the value of the button. It will change the original button's value but not the styled button. Is there any way I can connect the elements so that if the original button's value is changed the styled button's value is changed as well?

这是我的问题。假设用户有一个按钮。稍后在应用程序中,用户决定更改按钮的值。它将更改原始按钮的值,但不会更改样式按钮。有什么方法可以连接元素,这样如果更改原始按钮的值,样式按钮的值也会改变吗?

1 个解决方案

#1


you can catch any property change on object using onpropertychanged event.

您可以使用onpropertychanged事件捕获对象的任何属性更改。

$("#buttonid").bind('propertychange', function(e) {
    if (e.originalEvent.propertyName == "value") {
       // value is changed, handle it here      
    }
});

#1


you can catch any property change on object using onpropertychanged event.

您可以使用onpropertychanged事件捕获对象的任何属性更改。

$("#buttonid").bind('propertychange', function(e) {
    if (e.originalEvent.propertyName == "value") {
       // value is changed, handle it here      
    }
});