Javascript onclick函数不是第二次。错误消息为未捕获引用错误:未定义提交照片

Javascript onclick函数不是第二次。错误消息为未捕获引用错误:未定义提交照片,javascript,Javascript,该函数仅在第一次使用时有效,在刷新页面后不起作用。来自网站控制台的错误消息为: 未捕获引用错误:未定义提交照片AddDeletePhoto.php?附件id=2:1 onclick 未捕获的语法错误:意外标记非法 这是onlick html: <a data-role="button" data-theme="b" href=javascript:void(0)" onclick="submit_photo(); return false;"> U

该函数仅在第一次使用时有效,在刷新页面后不起作用。来自网站控制台的错误消息为:

未捕获引用错误:未定义提交照片AddDeletePhoto.php?附件id=2:1 onclick

未捕获的语法错误:意外标记非法

这是onlick html:

<a data-role="button" data-theme="b" href=javascript:void(0)" onclick="submit_photo(); return false;">
                  Upload
               </a>

这是JS:

   <script type="text/javascript">
        function submit_photo() {
            alert("test...");
            var allowedfilesize = 1024;
            var photo = document.getElementById('photo');
            var imagefilesize = Math.round(parseInt(photo.files[0].size) / 1024);

            if (imagefilesize > allowedfilesize) {
                photo.value = '';
                document.getElementById('errormessage').innerHTML = 'The file size is ' + imagefilesize + 'kB which is larger than the allowed size of ' + allowedfilesize + 'kB';
            } else {
                alert("uploading...");
                document.getElementById('errormessage').innerHTML = '';
                document.forms['addphoto'].submit();
                return false;
            }
        }
    </script>

函数submit_photo(){
警报(“测试…”);
var allowedfilesize=1024;
var photo=document.getElementById('photo');
var imagefilesize=Math.round(parseInt(photo.files[0].size)/1024);
如果(imagefilesize>allowedfilesize){
photo.value='';
document.getElementById('errormessage').innerHTML='文件大小为'+imagefilesize+'kB,大于允许的'+allowedfilesize+'kB'大小;
}否则{
警报(“上传…”);
document.getElementById('errormessage')。innerHTML='';
document.forms['addphoto'].submit();
返回false;
}
}

该函数是否第二次出现在页面上?您在
href=
之后缺少了一个
。是的,该函数第二次出现在页面上。添加了“但仍不工作”。