【问题标题】:How to access the JSF's SelectItem from jQuery or JavaScript如何从 jQuery 或 JavaScript 访问 JSF 的 SelectItem
【发布时间】:2011-12-31 04:29:15
【问题描述】:

有没有办法从 JavaScript 或 jQuery 访问 selectItem JSF 的 id?

<a:commandButton id="ajaxButton" value="change" onclick="selectCheck()">
</a:commandButton>

<h:selectManyCheckbox id="check" >
    <f:selectItem id="myCheckbox" itemLabel="India" itemValue="India"  />
    <f:selectItem itemLabel="China" itemValue="China" />
    <f:selectItem itemLabel="Germany" itemValue="Germany" />
    <f:selectItem itemLabel="USA" itemValue="USA" />
</h:selectManyCheckbox>

我尝试访问组件的 id 但它返回 null:

function selectCheck() {
    var obj = document.getElementById("myCheckbox");
    alert(obj);
    obj.checked=true;
}

我想通过 JavaScript 或 jQuery 动态检查这些复选框中的任何一个。

【问题讨论】:

标签: java javascript jquery jsf jakarta-ee


【解决方案1】:

您是否查看过生成的 html 是否真的是元素的 id? JSF 通常会在表单的 id 和其他一些容器元素之前添加。真实身份可能类似于myForm:myCheckbox

【讨论】:

  • 谢谢; html 为我的组件生成其他 id。它已解决
  • @ANIS:只要一个答案(大部分)有助于解决问题,您应该将其标记为已接受。另见How does accepting an answer work?。不要忘记查看您的previous questions,并在适用的情况下进行同样的操作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-25
  • 2010-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多