防止onclick向下级联

Prevent onclick from cascading down

本文关键字:级联 onclick 防止      更新时间:2023-09-26

我有一个自定义标记,它产生一个可点击的图像,该图像调用一个servlet来做一些"事情"。下面是标签产生的一个示例:

<c:set var="epMethodToCallAttribute" value="methodToCall.performLookup. ..."/>
${kfunc:registerEditableProperty(KualiForm, epMethodToCallAttribute)} 
<input type="image" tabindex="${tabindex}" name="${epMethodToCallAttribute}" src="${lookupicon}" border="0" class="tinybutton" valign="middle" alt="Search ${fieldLabel}" title="Search ${fieldLabel}" />

不幸的是,我不能真正改变标签库,所以我正在考虑做这样的事情:

<div id="searchIconDiv" onClick="if(confirm('Are you sure you want to do this?')){}"> 
  <c:set var="epMethodToCallAttribute" value="methodToCall.performLookup. ..."/>
  ${kfunc:registerEditableProperty(KualiForm, epMethodToCallAttribute)} 
  <input type="image" tabindex="${tabindex}" name="${epMethodToCallAttribute}" src="${lookupicon}" border="0" class="tinybutton" valign="middle" alt="Search ${fieldLabel}" title="Search ${fieldLabel}" />
</div>

但是要做到这一点,我需要做一些事情来捕获单击事件并防止它向下级联到标记产生的图像。什么好主意吗?

这是我建议的div标签所需的内容:

<div id="onClickDiv" onclick="return confirm('Are you sure?')">

从另一个Stackoverflow问题得到这个