0
if(isset($_POST['album_title'])) {
$album_title = $_POST['album_title'];
if($_FILES['pic_nr1']['type'] == 'image/jpeg' ||
    $_FILES['pic_nr1']['type'] == 'image/jpg' ||
    $_FILES['pic_nr1']['type'] == 'image/png' ||
    $_FILES['pic_nr1']['type'] == 'image/gif' &

    $_FILES['pic_nr2']['type'] == 'image/jpeg' ||
    $_FILES['pic_nr2']['type'] == 'image/jpg' ||
    $_FILES['pic_nr2']['type'] == 'image/png' ||
    $_FILES['pic_nr2']['type'] == 'image/gif' &

    $_FILES['pic_nr3']['type'] == 'image/jpeg' ||
    $_FILES['pic_nr3']['type'] == 'image/jpg' ||
    $_FILES['pic_nr3']['type'] == 'image/png' ||
    $_FILES['pic_nr3']['type'] == 'image/gif'
    ) {

    } else {
?>
<script type="text/javascript">
    document.getElementById("error_for_js").innerHTML = "Bilžu formāts nav derīgs!    <small> GIF, JPEG, JPG, PNG ir autļauti.</small>";
</script>
<?php

    }

}
?>


<form enctype="multipart/form-data" method='post' action='' onsubmit='if(document.getElementById("titleeee").value.length < 3 ) { document.getElementById("error_for_js").innerHTML = "Albūma nosaukumam ir jābūt garākam!"; return false; } else { return true; }'  >
     <p id='error_for_js'></p>
    Albūma nosaukums: <input id='titleeee' type='text' name='album_title' /><br />

    Bilde Nr 1: <input type='file' name='pic_nr1' /><br />
    Bilde Nr 2: <input type='file' name='pic_nr2' /><br />
    Bilde Nr 3: <input type='file' name='pic_nr2' /><br />

    Aktīvs*: <select>
                <option>Jā</option>
                <option>Nē</option>
            </select><br />
    <input  type='submit' value='Pievienot' />
</form>

我不明白为什么id='error_for_js'文件格式错误时不要改变的值,我做了getElementById('error_for_js').innerHTML = 'new value';但它没有改变!?想法?

4

1 回答 1

2

将您的 getElementById 包装为:

window.onload = function() {
   document.getElementById("error_for_js").innerHTML = "Hello!";
};

或在 HTML 元素之后添加脚本。

于 2012-08-28T19:11:14.773 回答