MooTools 1.4下getProperty(required)获取值实例页面

回到相关文章 »

代码:

CSS代码:
.demo pre{display:inline; margin:0;}
.co{color:#f30;}
.demo p{margin-top:2px;}
                
HTML代码:
<div class="demo">
    <pre>&lt;input id="input1" required /></pre> → <input id="input1" required />
    <p><code>$("input1").getProperty("required")</code> → <span id="result1" class="co"></span></p>
    <pre>&lt;input id="input2" /></pre> → <input id="input2" />
    <p><code>$("input2").getProperty("required")</code> → <span id="result2" class="co"></span></p>
</div>
                
JS代码:
[1,2].each(function(i, j) {
    var required = $("input" + i).getProperty("required");
    if (required === "") {
        required = "空字符串";
    }
    $("result" + i).set("html", required + "");
});
                

效果:

<input id="input1" required />

$("input1").getProperty("required")

<input id="input2" />

$("input2").getProperty("required")