ZK 属性 & 变量 & 客制属性

该怎设定 就怎取得
在XML 标准中, 标签上有attribute(属性)


<window>
<attribute name=”title”>My Window</attribute>
<attribute name=”border”>normal</attribute>
<attribute name=”width”>200px</attribute>
這是一個Window
</window>

  • 变量(已经舍弃)
  • 客制属性


    <zk>
    <zscript><![CDATA[
    public void test1() {

    result1.setValue(getData(div1.getAttribute("mykey")));
    result2.setValue(getData(div1.getVariable("mykey", false)));
    

    }
    public void test2() {

    result3.setValue(getData(div2.getAttribute("mykey2")));
    result4.setValue(getData(div2.getVariable("mykey2", false)));
    

    }
    public String getData(Object obj) {

    return obj == null ? "null" : (String) obj;
    

    }
    ]]></zscript>
    <hlayout>

    &lt;vlayout&gt;
        &lt;vlayout&gt;
    
            &lt;div id="div2" style="border: 1px solid red"&gt;
                &lt;custom-attributes mykey2="key2" /&gt;
                &lt;html&gt;&lt;![CDATA[ This is a DIV(div2) + &lt;br /&gt; &amp;lt;custom-attributes mykey2="key2" /&amp;gt; ]]&gt;&lt;/html&gt;
            &lt;/div&gt;
            &lt;button label="get Sth" onClick="test2();" /&gt;
        &lt;/vlayout&gt;
        &lt;hlayout&gt;
            div2 get attribute :
            &lt;label id="result3" value="" /&gt;
        &lt;/hlayout&gt;
        &lt;hlayout&gt;
            div2 get Variable :
            &lt;label id="result4" value="" /&gt;
        &lt;/hlayout&gt;
    &lt;/vlayout&gt;
    &lt;separator width="30px" /&gt;
    &lt;vlayout&gt;
        &lt;vlayout&gt;
            &lt;div id="div1" style="border: 1px solid green"&gt;
                &lt;variables mykey="key1" /&gt;
                &lt;html&gt;&lt;![CDATA[ This is a DIV(div1) + &lt;br /&gt; &amp;lt;variables mykey="key1" /&amp;gt; ]]&gt;&lt;/html&gt;
            &lt;/div&gt;
            &lt;button label="get Sth" onClick="test1();" /&gt;
        &lt;/vlayout&gt;
        &lt;hlayout&gt;
            div1 get attribute :
            &lt;label id="result1" value="" /&gt;
        &lt;/hlayout&gt;
        &lt;hlayout&gt;
            div1 get Variable :
            &lt;label id="result2" value="" /&gt;
        &lt;/hlayout&gt;
    &lt;/vlayout&gt;
    

    </hlayout>
    </zk>