You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在行内onclick事件的函数调用中前置添加event.stopPropagation()

问题修复方案

核心错误点

  • 拼写错误:DOM事件阻止冒泡的标准API正确写法是event.stopPropagation(),错误写法StopPropogating存在拼写偏差、首字母大写不符合规范两个问题
  • 行内onclick事件需要按执行顺序先写阻止冒泡逻辑,再调用自定义业务函数

修复后可运行代码

$(".select2-selection__rendered").append('<li class="select2-selection__choice" id="remove_test'+i+'"  title="'+rows_value+'"><span class="select2-selection__choice__remove" onclick="event.stopPropagation();remove_e('+i+');" role="presentation">x</span>'+title_name_test+'</li> ');

补充说明

如果变量i是字符串类型而非数字类型,需要给remove_e的参数补充单引号转义,修改为remove_e(\''+i+'\')即可。

内容的提问来源于stack exchange,提问作者Bilal Hameed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 21:39:03