小编Mic*_*ati的帖子

稍后在同一文件中定义的派生类"不存在"?

假设我们有两个php文件,a.php和b.php这里是文件a.php的内容:

<?php // content of a.php
class A {
}
Run Code Online (Sandbox Code Playgroud)

这是文件b.php的内容

<?php  // content of b.php
include dirname(__FILE__) . "/a.php";
echo "A: ", class_exists("A") ? "exists" : "doesn’t exist", "\n";
echo "B: ", class_exists("B") ? "exists" : "doesn’t exist", "\n";
echo "BA (before): ", class_exists("BA") ? "exists" : "doesn’t exist", "\n";
echo "BB: ", class_exists("BB") ? "exists" : "doesn’t exist", "\n";
class B {
}
class BA extends A {
}
class BB extends B {
}
echo "BA (after): …
Run Code Online (Sandbox Code Playgroud)

php extends class require include

18
推荐指数
1
解决办法
1789
查看次数

checkValidity / reportVality 不适用于通过代码设置的值

如果通过 JavaScript 设置值, HTML5 checkValidity()/reportValidity()方法似乎不起作用。

考虑这个例子(JSFiddle):

<input id="text-field" maxlength="3" placeholder="Max len: 3 chars" />
<button id="set-field-value">Set</button>
<button id="check-valid">Is valid?</button>
<script>
window.onload = function() {
    var textField = document.getElementById('text-field');
    document.getElementById('set-field-value').onclick = function() {
        textField.value = 'This is a very looooooooooooooooooooooooooooooong text';
    };
    document.getElementById('check-valid').onclick = function() {
        window.alert(textField.checkValidity());
    };
};
</script>
Run Code Online (Sandbox Code Playgroud)

如果单击该Set按钮,输入字段的值将设置为无效值(长度大于 3 个字符),但该checkValidity()方法仍然表明输入有效(在 Chrome、Edge 和 Firefox 上检查)。

为什么?有没有办法确定该字段是否有效,即使其值是通过代码设置的?

html javascript

5
推荐指数
1
解决办法
2853
查看次数

标签 统计

class ×1

extends ×1

html ×1

include ×1

javascript ×1

php ×1

require ×1