gpt4 book ai didi

javascript - AUI 复选框未显示为已选中但值为 true

转载 作者:行者123 更新时间:2023-11-30 17:25:24 24 4
gpt4 key购买 nike

我有一个复选框。

<aui:input name = "enable" id = "enable" type="checkbox" label= 'Enable'  onchange='handleClick(this);' />

我在页面加载时加载复选框的先前状态。检查之前的状态后,我执行以下操作。

var namespace = "<portlet:namespace/>";
window.onload = function() {
var cb = document.getElementById(namespace+ "enable");
cb.checked = true;
alert("state: " + cb.checked);
//do something
};

警报显示复选框为 true,它会执行后面的代码。但是, View 不显示要选中的复选框!我错过了什么?

最佳答案

AUI Input 是好是坏即,它会自动将 Checkbox 附加到 input:checkbox 的 ID .

<input type="checkbox" onchange="handleClick(this);" value="true" onclick="Liferay.Util.updateCheckboxValue(this); " name="_manageorganization_WAR_manageorganizationportlet_enableCheckbox" id="_manageorganization_WAR_manageorganizationportlet_enableCheckbox" class="aui-field-input aui-field-input-choice">

在你的情况下,你的 "<portlet:namespace/>"; ,它生成的 id 为:

namespace+ "enableCheckbox"

所以用它作为:

var namespace = "<portlet:namespace/>";
window.onload = function() {
var cb = document.getElementById(namespace+ "enableCheckbox");
cb.checked = true;
alert("state: " + cb.checked);
//do something
};

它会起作用。

关于javascript - AUI 复选框未显示为已选中但值为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24381194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com