如果使用jQuery更改了值,jquery change()将不起作用 [英] jquery change() doesnt work if the value is changed using jQuery

查看:599
本文介绍了如果使用jQuery更改了值,jquery change()将不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本输入字段,该字段已设置为只读,因此用户无法在其中输入内容.我虽然用jquery更新了它的值.因此,基本上,我希望事件在使用jQuery更改值时触发.以下是输入标记和jquery标记的示例.

I have a text input field which i have made readonly so the user can't type into it. I update the value of it with jquery though. So basically I want an event to fire when its value gets changed using jQuery. Below is an example of the input markup and jquery markup.

<input type="text" readonly="readonly" id="textinput" />

$('#textinput').change(function() {
    alert("It's Changed!");
});

推荐答案

您将无法执行此操作.通过代码进行的更改不会触发事件.您可以直接在代码中直接调用change.

You won't be able to do this. Changes made through code do not trigger events. You can simply call change directly in your code.

类似这样的东西:

// do stuff
$('#textinput').val("something").change();

这篇关于如果使用jQuery更改了值,jquery change()将不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆