简体   繁体   English

我应该在 onclick 上放置什么事件?

[英]what should i put event on onclick?

<img src="image1.png" onclick="handler(this.src)" />

function handler(event, handler_src){
  if(onClickOn){
    companyJes(handler_src);
  }else{
    event.preventDefault(); // don't do anything
    event.stopPrpagation(); // really don't do anything

    return false; //make sure you don't do anything
  }
}

on the onclick handler(what should i put this ?, this.src);在 onclick handler(what should i put this ?, this.src); what should i put variable on onclick to replace the event ?我应该在 onclick 上放置什么变量来替换事件?

i tested handler(event, this.src);我测试了handler(event, this.src); but it didt work.但它没有工作。

You need to pass the event object in the handler.您需要在处理程序中传递事件对象。 Eg:例如:

handler(event)

Because "this" will the HTML element which called the handler function因为“this”将调用处理程序函数的 HTML 元素

See the JSFiddle查看JSFiddle

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

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