简体   繁体   English

JavaScript,onclick事件未响应

[英]JavaScript, onclick-event not responding

I hope to get a simple and straight answer as this is driving me crazy. 我希望得到一个简单而直接的答案,因为这使我发疯。 I know this isn't the best way of doing this but I just can't figure out, why these two lines behave differently: 我知道这不是执行此操作的最佳方法,但是我不知道为什么这两行的行为会有所不同:

First line, working fine: 第一行,工作正常:

<img id="hellig_del42736" src="../images/kryds.png" title="Slet helligdagen den 01-01-2017..." alt="Slet helligdagen den 01-01-2017..." onclick="if(confirm('Vil du slette helligdagen den 01-01-2017?')){document.getElementById('helligid42736').style.textDecoration='line-through';hasChanged=false;window.location.href='/admin/admin.asp?vacfrom='+(25569+(new Date(document.getElementById('feriefra').value).getTime()/1000/86400))+'&delbankhd=42736&page=2&sid=feriefra'}" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor=''">

Second line, not responding - sometimes resulting in "member not found-error" - sometimes works if debugging (F12) is open: 如果调试(F12)打开,则第二行不响应-有时会导致“ member not found-error”(成员未找到错误)-有时可以工作:

<img id="blockedip_del8" src="../images/kryds.png" title="Fjern blokeringen af IP# 5.6.7.8 (mail@mail.dk)..." onclick="if(confirm('Vil du fjerne blokeringen af IP# 5.6.7.8 (mail@mail.dk)?')){document.getElementById('blockid8').style.textDecoration='line-through';hasChanged=false;window.location.href='/admin/admin.asp?delblockedip={93F17D3B-7FA1-48F1-8792-K52E30273818}&page=5&sid=deadlinetime'}" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor=''">

I have tried several thing inside the comfirm()-statement (second line): 我已经在comfirm()语句(第二行)中尝试了几件事:

  • Removed paranthesis with no difference 删除了无意识
  • Removed hashtag with no difference 删除主题标签没有区别
  • Ensured that there are no conflicting id's 确保没有冲突的ID

These lines are to my best knowledge codewise identical yet they behave differently. 就我所知,这些行在代码方面是相同的,但它们的行为却有所不同。

I know I can put all the statements in a function and that "I really shouldn't..." but if this is how I want it, how can I fix it? 我知道我可以将所有语句放在一个函数中,并且“我真的不应该...”但是如果这是我想要的方式,该如何解决呢?

Thanks, 谢谢,

I'm an idiot! 我是个白痴!

For some idiotic reason I had used id="confirm" on a form element within the same form and changing that reserved word to id="confirmation" solved everything. 由于某种愚蠢的原因,我在同一表单内的表单元素上使用了id =“ confirm”,并将保留字更改为id =“ confirmation”解决了所有问题。

I thought I checked everything but I hadn't. 我以为我检查了所有东西,但没有检查。 Only removing elements one by one and testing led to the error. 仅一个接一个地删除元素并进行测试才导致错误。

Thanks "idmean" for pointing me to the surrounding code. 感谢“ idmean”为我指出了周围的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM