每次单击后Javascript事件都会递增
我在菜单中有一些锚定标记作为列表项,在每个项上我都添加了一个名为patient on change的类 我的链接正在这里生成>>>每次单击后Javascript事件都会递增,javascript,jquery,ractivejs,Javascript,Jquery,Ractivejs,我在菜单中有一些锚定标记作为列表项,在每个项上我都添加了一个名为patient on change的类 我的链接正在这里生成>>> {{#each nodeList}} {{#detail}} <li> {{#if mayBeLeaf}} <a href="/${controllerName}/{{type}}/{{originId}}" class="hasGlyphicon{{#if noLink}} menuNoLink{{
{{#each nodeList}}
{{#detail}}
<li>
{{#if mayBeLeaf}}
<a href="/${controllerName}/{{type}}/{{originId}}" class="hasGlyphicon{{#if noLink}} menuNoLink{{/if}}">
{{nodeNm}}
<span class="glyphicon glyphicon-expand pull-right" title="Click icon to expand menu"
data-action="expand"
data-ctrl="${controllerName}"
data-node-id="{{nodeId}}"<%-- node-id translates to nodeId in the JavaScript data property --%>
data-origin-id="{{originId}}"<%-- origin-id translates to originId in the JavaScript data property --%>
data-type="{{type}}"
data-level="{{level}}"
data-row="{{row}}"></span>
</a>
{{else}}
<a class="patient-on-change" href="/${controllerName}/{{type}}/{{originId}}">
{{#if detail.flagDt}}<span title="Care Notes Complete" class="glyphicon glyphicon-ok-sign"></span>{{/if}} {{nodeNm}}</a>
{{/if}}
</li>
{{/detail}}
{{/each}}
现在的问题是,在第一次单击某个项目时,它并没有触发该操作。但从第二次开始,它会触发该操作,但每次我单击某个项目时,该警报每次都会增加1。我不能在这里使用e.preventDefault,因为我需要运行一些代码。谁能帮我一下吗?你的代码有一个不必要的}。应该是这样的
$('a.patient-on-change').on('click', function(e){
alert('hello');
});
你能创建一个例子来演示吗?每次点击都会再次执行该代码或类似的东西。问题中没有足够的代码来准确说明问题所在。您没有正确关闭单击事件。删除额外的右括号和tryHI,是jQuery还是Angular?你能举个例子吗?额外的}是一个打字错误
{{#each nodeList}}
{{#detail}}
<li>
{{#if mayBeLeaf}}
<a href="/${controllerName}/{{type}}/{{originId}}" class="hasGlyphicon{{#if noLink}} menuNoLink{{/if}}">
{{nodeNm}}
<span class="glyphicon glyphicon-expand pull-right" title="Click icon to expand menu"
data-action="expand"
data-ctrl="${controllerName}"
data-node-id="{{nodeId}}"<%-- node-id translates to nodeId in the JavaScript data property --%>
data-origin-id="{{originId}}"<%-- origin-id translates to originId in the JavaScript data property --%>
data-type="{{type}}"
data-level="{{level}}"
data-row="{{row}}"></span>
</a>
{{else}}
<a class="patient-on-change" href="/${controllerName}/{{type}}/{{originId}}">
{{#if detail.flagDt}}<span title="Care Notes Complete" class="glyphicon glyphicon-ok-sign"></span>{{/if}} {{nodeNm}}</a>
{{/if}}
</li>
{{/detail}}
{{/each}}
$('a.patient-on-change').on('click', function(e){
alert('hello');
});