모든 입력이 채워 졌는지 확인하는 자바 스크립트가 포함 된 PHP 파일 (양식)이 있습니다. PHP 파일을 직접 볼 때 js가 완벽하게 작동하지만 다른 페이지에 PHP 파일을 포함하면 자바 스크립트가 더 이상 작동하지 않습니다.포함 된 PHP 파일의 자바 스크립트
내 자바 스크립트 코드 :
<script type="text/javascript" src="../js/modernizr.js"></script>
<script type="text/javascript">
window.onload = function(){
document.getElementById("topField").setAttribute("autocomplete","off");
}
window.onload = function() {
// get the form and its input elements
var form = document.forms[0],
inputs = form.elements;
// if no autofocus, put the focus in the first field
if (!Modernizr.input.autofocus) {
inputs[0].focus();
}
// if required not supported, emulate it
if (!Modernizr.input.required) {
form.onsubmit = function() {
var required = [], att, val;
// loop through input elements looking for required
for (var i = 0; i < inputs.length; i++) {
att = inputs[i].getAttribute('required');
// if required, get the value and trim whitespace
if (att != null) {
val = inputs[i].value;
// if the value is empty, add to required array
if (val.replace(/^\s+|\s+$/g, '') == '') {
required.push(inputs[i].name);
}
}
}
// show alert if required array contains any elements
if (required.length > 0) {
alert('The following fields are required: ' +
required.join(', '));
// prevent the form from being submitted
return false;
}
};
}
}
</script>
를? – datasage
JS 콘솔에서 오류가 있는지 확인하십시오. –
동일한 디렉토리 수준의 PHP 파일에 포함 시키시겠습니까? 스크립트 경로에주의하십시오. –