如何在javascript中执行回调后替换属性并保留它?



我是javascript的新手。所以,我需要一些帮助。 我在WebForm上有ASPxGridView,我想在单击"清除"按钮时运行我的代码。我的意思是ASPxGridView中的嵌入式按钮,它放置在SearchPanel中。所以,我把这段代码放在javascript中:

window.onload = function (s, e){
document.getElementById("gridFileList_DXCBtn1").removeAttribute("data-args");
document.getElementById("gridFileList_DXCBtn1").setAttribute("onclick", "gridFileList.PerformCallback();");
}

它工作得很好,但是在回调之后,当我再次单击此按钮时,我的代码不会再次运行,我看到,此按钮再次具有其属性"data-args",并且没有我的属性"onclick"。

回调后 Window.onload 不会触发,所以你能解释一下我需要使用什么事件来描述该按钮上的行为吗?

好的,我发现每次按下按钮时看起来都像是重新创建的。所以我做了一个把戏。我在正文部分写了

<body onclick="OnClick(event);">

在脚本部分:

function OnClick(e) {
if (e != undefined && e.target.className == "dx-vam" && e.target.localName == "span" && e.target.textContent == "Очистить") {
var btn = e.target.parentElement.parentElement;
if (btn.attributes[btn.attributes.length - 1].name == "data-args") {
btn.removeAttribute("data-args");
}
gridFileList.PerformCallback();
}
}

最新更新