2015-09-30 48 views
0

我有这样的Java脚本代码是jQuery的如何将Jsf Bean变量值传递给Jquery/JavaScript?

<script> 
    function initReportExplr() { 
    alert(jQuery('#inputValues').val()); 

    } 
    $(document).ready(function() { 
    initReportExplr(); 
    }); 
    </script> 

页上的电话,这是部分我使用

<h:inputText id="inputValues" value="#{reportsBean.birtServerInformation}"/> 

和内获得方法,我初始化变量

public String getBirtServerInformation() { 
     StringBuilder birtInfo = new StringBuilder(); 
     birtInfo.append(Constants.BIRT_SERVER_URL); 
     birtInfo.append(","); 
     birtInfo.append(Constants.BIRT_SERVER_PORT); 
     birtInfo.append(","); 
     birtInfo.append(Constants.BIRT_USER_NAME); 
     birtInfo.append(","); 
     birtInfo.append(Constants.BIRT_PASSWORD); 
     birtServerInformation = birtInfo.toString(); 
     return birtServerInformation; 
    } 

但是,当我尝试按此代码打印值时,我得到undefinedalert(jQuery('#inputValues').val());

+1

你看到了什么,当你只能做'的jQuery('#inputValues “)'?并且不要使用'alert()'进行调试,使用'console.log()'并查看'F12'控制台中的日志。如果你的''在''内,那么id也包含命名容器ID。使用检查这个领域,并检查客户端ID,然后它应该工作。 – Geinmachi

+0

@Geinmachi我得到'语法错误,无法识别的表情:不支持的伪:reportsForm1'尝试这个代码\t \t \t \t'的jQuery( '#contentform:reportsForm1:inputValues');' –

+0

你要逃避':'以\\ ,'jQuery('#contentform \\:reportsForm1 \\:inputValues')。val()' – Geinmachi

回答

0

正如@Geinmachi提到的jQuery的这一种解决方案是

jQuery('#contentform\\:reportsForm1\\:inputValues').val(); 

,并通过JavaScript另一种方式是

document.getElementById("contentform:reportsForm1:inputValues").value; 
相关问题