只读时TextBox的Fire

只读时TextBox的Fire

本文介绍了只读时TextBox的Fire onchange事件为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在只读的文本框中改变一些功能。
但是当我尝试更新使用JavaScript的文本框时,更改事件不会触发文本框。

I am trying to have some functionality on change of a textbox which is readonly.But when I am trying to update the textbox using javascript, the change event is not firing for the textbox.

<script type="text/javascript">
        $(document).ready(function () {
            $('input[id$=_txtTest]').bind("change", function () {
                alert("test");
            });
                        });
        function ChangeText() {
            $('input[id$=_txtTest]').val('hello');
         }
    </script>

我点击按钮调用ChangeText方法。但它并没有触发文本框的textchange事件。

I am calling ChangeText method on click of a button. But it is not firing the textchange event for the textbox.

有人可以告诉我这里有什么问题吗?

Can anybody tell me what is wrong here?

推荐答案

你必须这样做:

 $(document).ready(function () {
   $('input[id$=_txtTest]').bind("change", function () {
     alert($(this).val());
   });
   $('button').bind("click", function () {
     $('input[id$=_txtTest]').val('hello').trigger('change');
   });
 });

这篇关于只读时TextBox的Fire onchange事件为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:19