jQuery / Javascript - 如何在更改按鈕值時觸發事件?

[英]jQuery/Javascript - How to fire an event when a button's value is changed?


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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/05/30/30c892efce2a11784d0c21a1a33ac314.html



 
  © 2014-2022 ITdaan.com 联系我们: