javascript - 在 Jquery 中记录 $(this).val()
问题描述
我发现了一个在输入字段更改值时记录的小提琴。但是我也想记录新值。我已经尝试了我在网上找到的所有组合,但无法让它发挥作用。这是一个小提琴:https ://jsfiddle.net/Xezmb/8/
指数
<input type="number" id="n" value="5" step=".5"/>
脚本
$(":input").bind('keyup change click', function (e) {
if (! $(this).data("previousValue") ||
$(this).data("previousValue") != $(this).val()
)
{
console.log("changed");
$(this).data("previousValue", $(this).val());
}
});
$(":input").each(function () {
$(this).data("previousValue", $(this).val());
});
解决方案
您可以通过更改共享代码的第 6 行来做到这一点。
从:
console.log("changed");
至:
console.log("changed: ", $(this).val() );
推荐阅读
- python - 这个传感器数据的最佳数据结构是什么?
- java - 需要获取浏览器日志。但是正在发生“java.lang.IllegalArgumentException”错误。如何清除此错误?
- cmake - 将 CMake 目标定义传播到链接库
- reactjs - NextJS getStaticProps() 没有从表单值更新
- realex-payments-api - 全球支付 - 沙盒 url 交易日志
- r - 在没有图例的情况下将比例渐变颜色应用于 R 中的条形图
- oracle - Oracle Apex如何在页面的SQL中访问用户(:APP_USER)的角色
- sql - 计算全小时费用总和
- java - 如何在apache2中为spring boot中的嵌入式tomcat服务器配置反向代理?
- vue.js - vueform/multiselect 不能作为单个文件组件工作