我在 java 脚本中有一个字典,在拖动事件中添加键和文本。
现在,当用户单击此键时,必须删除该键,但不会从字典中删除
var buttonId = {};
function drag(ev) {
//buttonId.push(ev.target.id,ev.target.innerText);
var index = Object.keys(buttonId).length;
buttonId['[' + index + '].Key'] = ev.target.id;
buttonId['[' + index + '].Value'] = ev.target.innerText;
}
删除功能
function Delete(key){
delete buttonId[key];
}
spliceMethod也不起作用,我使用的是 Jquery 2.0,出现运行时错误 Object doesn't support property or method 'splice'
var length = Object.keys(buttonId).length;
for (var index = 0; index < length; index++) {
var key = buttonId['[' + index + '].Key'];
if (key == id) {
buttonId.splice(index, 1);
}
}