javascript - 点击 2 个 id 更新 .map() 数组 jquery
问题描述
如何在第二个按钮单击时更新 .map(maped) 数组。我需要存档的是第二个按钮单击更新数组。
我需要注意变化,然后再打电话.map()
。
$("#send, #more_column").click(function(e) {
if (this.id == 'more_column') {
console.log("Second button click"); //im inside second button click
// here i need to update the device_id[] array add one more item to array or more
}
device_id = $('input:enabled[name="device_id[]"]').map(function() {
return $(this).val(); // $(this).val()
}).get();
});
单击第二个按钮时如何更新device_id数组。如果再次单击第二个按钮,则再次更新device_id数组。
有任何想法吗 ?
解决方案
在这种情况下,混合事件处理程序没有意义。最好保持代码简单,所以有一个添加按钮的事件处理程序和一个发送按钮的事件处理程序,并使添加按钮也调用发送处理程序......
function send() {
device_id = $('input:enabled[name="device_id[]"]').map(function() {
return $(this).val(); // $(this).val()
}).get();
}
function add() {
// add whatever you need to add here
// execute the "send" handler...
send();
}
$("#send").on("click", send);
$("#more_column").on("click", add);
推荐阅读
- android - CameraX ML KIT 给出错误“java.lang.IllegalStateException:图像已关闭
- apache-spark - Nvidia Spark-XGBOOST
- python - raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: ''
- python - problem importing CPX library to use Device Simulator or Visual Sudio Code
- mysql - 有没有办法跟踪 web 应用程序在 mysql 服务器中进行的调用?
- tensorflow - DNN 不同部分的不同损失函数
- sql-server - 将 varchar(max) 中的非十六进制文本转换为 varbinary
- google-bigquery - BigQuery 使用条件从其他表创建表(管理大量列)
- java - Maven多线程构建问题
- emeditor - Em-Editor 自定义 TSV