0
我想显示警报如果输入值更改。我正在使用jQuery,所以这里是一个演示,我正在尝试做,但警报不显示/不工作。由于如何显示警报何时/如果输入值实时更改使用jQuery?
$(".d1, .d2").click(function (e) {
var $this = $(this);
$(".input").attr('value', $this.text());
});
$(".input").change(function() {
alert(this.value);
});
.d1, .d2 {cursor:pointer;border:1px solid black;margin-top:10px;padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<input class="input" value="" /><p/>
<a class="d1">Demo 1</a>
<a class="d2">Demo 2</a>
呼叫改变()事件设定值后直接。如:$(“。input”)。attr('value',$ this.text())。change(); –