javascript - 如何返回“onclick”属性?
问题描述
如果我删除一个onclick
属性,我如何将它设置回与事件中应用的第一个函数相同的元素上onclick
。
例如function show(clicked_id)
// 通过点击获取用户 ID。
我不希望用户在同一个 ID 上单击两次,所以我使用一个remove
属性。然后我想把它改回原来的样子。
function getthepic(m) {
GetPic.setAttribute("src", randomImages[m]);
x.appendChild(GetPic);
StorePics[i] = randomImages[m];
StoreIds[i] = x;
counter++;
i++;
CheckValve = false;
StoreIds[0].removeAttribute("onclick");
}
setTimeout(function() {
if (counter == 2) {
StoreIds[0].innerHTML = "";
StoreIds[1].innerHTML = "";
var getCard = document.createElement('img');
getCard.setAttribute("src", 'images/blank.png');
StoreIds[0].appendChild(getCard);
var getCard2 = document.createElement('img');
getCard2.setAttribute("src", 'images/blank.png');
StoreIds[1].appendChild(getCard2);
counter = 0;
i = 0;
StorePics[0] = "";
StorePics[1] = "";
StoreIds[0] = "";
StoreIds[1] = "";
StorePics.pop();
StoreIds.pop();
StorePics[0].setAttribute('onclick', show(clicked_id);
}
CheckValve = true;
}, 1000);
解决方案
推荐阅读
- c# - Unity2D 中的实时实现
- powershell - 为什么尾随反斜杠会破坏 Powershell 参数解析?
- javascript - javascript动态多输入
- arrays - 在工作表中的任意位置查找值并返回其正下方的单元格
- vba - 使用 MC Access 创建文件夹并根据表单中的字段将 MS Word Doc 保存在文件夹中
- python - 将 NoneType 转换为字符串的条件
- vulkan - 组合图像采样器与分离采样图像和采样器
- python - 我应该如何提高 SymPy 输出的图像的分辨率?
- javascript - React.js 解析错误:相邻的 JSX 元素必须包含在封闭标记中。你想要一个 JSX 片段 <>...?
- python - 使用 github 操作将 python 生成的图提交到 repo