如何触发与AUI链接的onclick javascript?

时间:2014-11-28 12:12:23

标签: javascript yui liferay-aui

我有一个隐藏的链接,其中包含我需要调用的生成的javascript片段:

var AUI = YUI;
AUI().use('event', function(A) {
var deleteButton = 46;
A.one('.searchNameSelect').on('keyup', function(e) {
if(e.button == deleteButton){
    A.one('a.deleteSelectedSearch')._node.onclick();
}
});
});
<script src="http://cdn.alloyui.com/2.0.0/aui/aui-min.js"></script>
<a href="#" onclick="alert('call successful');" class="deleteSelectedSearch" style="display:none;"></a>
<select name="selectedSearch" size="1" class="searchNameSelect">
 <option value="search">search</option>
 <option value="another-search" selected="selected">another-search</option>
</select>

使用MyFaces(2.1)commandLink生成链接 <h:commandLink class="deleteSearch" action="#{search.deleteSelected}"></h:commandLink> 它生成一个onclick javascript:onclick="return myfaces.oam.submitForm('genertated-formId','generated');

我尝试使用AUI触发click事件,但没有成功。

有没有人有一个好主意以更AUI风格的方式触发onclick Javascript?

1 个答案:

答案 0 :(得分:4)

您需要使用&#39; node-event-simulate&#39;模块并将其命名为

A.one('a.deleteSelectedSearch').simulate('click');

这是修改后的代码

var AUI = YUI;
AUI().use('event', 'node-event-simulate', function(A) {
var deleteButton = 46;
A.one('.searchNameSelect').on('keyup', function(e) {
    if(e.button == deleteButton){
        A.one('a.deleteSelectedSearch').simulate('click');
    }
});
});

Working Fiddle