【问题标题】:how to get the updated value in JavaScript如何在 JavaScript 中获取更新后的值
【发布时间】:2013-05-29 09:22:50
【问题描述】:

我有一个 jquery 文件:

document.getElementById('formId:someId').click();
bla = document.getElementById('formId:inputId3').value;            
              if(bla =="koko") {
 alert(" Done ");
 }

在 jsf 中,我有改变 h:inputText 值的方法:

 <h:inputText id="inputId3" value="#{gestionduplanning.testvalue2}" />

 <h:commandButton id="someId" value="Button" action="#{gestionduplanning.exec2()}" style="display:none">
 <f:ajax render="inputId3" execute="@all"/>  
 </h:commandButton>

在托管 bean 中我有:

   public void exec2() {
    this.testvalue2 = "koko";    
   }

我无法在 Jquery 中输入 if 的问题,因为它们在更改之前仍然具有第一个默认值。

如何在单击按钮之前更新 Jquery 中的 inputText 更新??

【问题讨论】:

  • 您调用 jQuery 的部分只是纯 JavaScript。你似乎根本没有使用 jQuery,所以我删除了那个标签。
  • 我也更新了标题
  • @marouanoviche,这可能有帮助吗? stackoverflow.com/a/16444123/617373
  • 你认为我的逻辑有问题,当他已经吃过午餐时,Javascript 无法获得新值?

标签: javascript jsf


【解决方案1】:

你的代码应该是这样的(它的总体思路):

document.getElementById('formId:someId').click();

并添加如下js函数:

function doTheJs(data) {
    if (data.status === 'success') {
        bla = document.getElementById('formId:inputId3').value;            
        if(bla =="koko") {
            alert(" Done ");
        }
    }
}

和你的 JSF:

<h:commandButton id="someId" value="Button" action="#{gestionduplanning.exec2()}" style="display:none">
    <f:ajax render="inputId3" execute="@all" onevent="doTheJs"/>  
</h:commandButton>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多