gpt4 book ai didi

jquery - 是否可以找到触发 .change() 的值?

转载 作者:行者123 更新时间:2023-11-30 23:58:54 25 4
gpt4 key购买 nike

来自<select>标签,是否可以找到 .change() 的值被触发了吗?

最佳答案

使用变量来缓存以前的值。

// bind change event handler to the eleemnt 
// and cache the current value in `prev`
var prev = $('#test').change(function() {
// get previous value from `prev`
console.log('prev : ' + prev + ' , current : ' + this.value);

//... do the rest here

// update the `prev` variable with current value
prev = this.value;
}).val(); // get the default value
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="test">
<option value="1">1</option>
<option value="11">11</option>
<option value="111">111</option>
</select>

关于jquery - 是否可以找到触发 .change() 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40905176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com