如何使用 CSJS 禁用 xPage 面板

how to disable xPage panel with CSJS

我正在尝试使用 CSJS 禁用我的 xPage 上的一个面板。但是这两种方法都不起作用:

dojo.byId("#{id:panel1}").readonly=true;
dojo.attr("#{id:panel1}", "readonly", "true");
document.getElementById("#{id:panel1}").setAttribute("readonly", "true");

为面板中的所有输入元素设置 .attr('disabled', 'disabled');

<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:panel
        id="panel1">
        <xp:inputText
            id="inputText1"
            value="#{sessionScope.Test}"></xp:inputText>
    </xp:panel>
    <xp:br></xp:br>
    <xp:button
        value="Disable Input Field On Client Side"
        id="button1">
    <xp:eventHandler
        event="onclick"
        submit="false">
        <xp:this.script><![CDATA[
            var panel1 = document.getElementById("#{id:panel1}");
            dojo.query('input', panel1).attr('disabled', 'disabled');
        ]]></xp:this.script>
    </xp:eventHandler></xp:button>
</xp:view>

dojo.query('input', panel1) returns 面板 1 中所有输入元素的集合。

.attr(...) 将属性设置为每个集合的元素。

如果您也想禁用面板中的其他元素,只需将元素的类型添加到查询中,例如 dojo.query('input, button', panel1) 用于按钮。