我有一个可点击的div
,我想在某些情况下禁用它。
<div id="div" routerLink="/url" class="module-dashboard"></div>
我试过了:
var div= <HTMLDivElement>document.getElementById("div");
div.disabled = true;
但“已禁用”不属于HTMLDivElement
我需要避免使用routerLink
。
有可能吗?
答案 0 :(得分:1)
removeEventListener()
方法删除已使用addEventListener()
方法附加的事件处理程序。
var _el = document.getElementById("div");
_el.removeEventListener("click", eventHandler);
此处eventHandler
是您使用addEventListener
点击时附加的功能。像"element.removeEventListener("event", function(){ myScript })
这样的匿名函数不起作用。
答案 1 :(得分:0)
试试这个。点击只会工作一次。
var currencyCodes = new List<string>() { "USD", "SGD", "KWD", "BHD", "LYD" };
var currencies = new List<Currency>()
{
new Currency() { CurrencyName = "USD (SMALL)",CurrencyCode = "USD SMALL",BranchName="Branch1"},
new Currency() { CurrencyName = "SGD BIG",CurrencyCode = "SGD BIG",BranchName="Branch1"},
new Currency() { CurrencyName = "KUWAIT DINAR",CurrencyCode = "KWD",BranchName="Branch1"},
new Currency() { CurrencyName = "USD BIG (100,50)",CurrencyCode = "USD BIG",BranchName="Branch1"},
new Currency() { CurrencyName = "USD MEDIUM (10,20)",CurrencyCode = "USD MEDIUM",BranchName="Branch1"},
};
List<CurrencyMap> maps = currencies.Select(c => new
{
Currency = c,
FoundCode = currencyCodes.FirstOrDefault(code => c.CurrencyCode.Contains(code))
})
.Where(o => o.FoundCode != null)
.GroupBy(o => o.FoundCode)
.Select(grp => new CurrencyMap() { Code = grp.Key, Currencies = grp.Select(o => o.Currency).ToList() })
.ToList();
&#13;
var e = document.getElementById("button");
e.onclick = function() {
this.onclick = null;
console.log("disabled!");
};
&#13;