调用单击(隐藏)按钮或链接的Javascript函数 [英] calling a Javascript function that makes a click on a (hidden) button or link

查看:54
本文介绍了调用单击(隐藏)按钮或链接的Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调用一个javascript函数,该函数单击一个隐藏的commandButton,但是单击会在页面加载时运行,而不是在我调用该函数时运行. 这是html代码:

I call a javascript function that makes a click on a hidden commandButton but the click run when the page loads, not when I call the function. this is the html code :

<p:inputText id="aa" value="#{bonBonneManagedBean.sel}" onkeyup="fnc()" />
<h:commandButton id="hh" onclick="#{bonBonneManagedBean.kk()}" style="display:none"/>

和javaScript函数:

and the javaScript function :

function fnc()
{
    length = document.getElementById('form:aa').value.length;
    if(length == 10)
    {
        $("#hh").click();
        document.getElementById('form:aa').value = "";
    }
}

推荐答案

您应使用action属性而不是onclick这样的

You should use the action attribute instead of onclick like this

<h:commandButton id="hh" action="#{bonBonneManagedBean.kk()}" style="display:none"/>

请注意,您可能需要像这样向选择器添加表单前缀

Note that you might have to add form prefix to the selector, like this

$("#myFormId\\:hh").click();

对于commandLink或任何其他可点击的"组件也一样.

The same would work for a commandLink or any other 'clickable' component.

这篇关于调用单击(隐藏)按钮或链接的Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆