양식을 제출할 때 자바 스크립트 함수가 작동하도록하려고하는데 함수가 실행되지 않는 것 같습니다. 누구든지 도울 수 있습니까?
<html>
<head>
<script>
function upload(){
alert("I am an alert box!");
}
</script>
</head>
<body>
<form enctype="multipart/form-data" method="post" onsubmit="return upload();">
<input type="file" name="file">
<input type="submit" name="upload" value="Datei hochladen">
</form>
</body>
</html>
이벤트 핸들러를 양식 요소에 연결할 때 이벤트 핸들러의 범위는 창이 아니라 양식입니다.
<form enctype="multipart/form-data" method="post" onsubmit="return upload(this);">
<script>
function upload(scope) {
console.log(scope); // The passed scope from the event handler is
} // the form, and not window
</script>
양식 내부의 입력 요소가 양식 객체에 속성으로 첨부되므로 이름이 키인 upload()
이벤트 처리기에서 호출 ( 범위가 양식)은 호출 form.upload()
과 같지만 양식에는 이미 해당 이름을 가진 요소가 있으므로 전역 범위 form.upload
의 upload()
기능 이 아니라 업로드 버튼 입니다.
이를 해결하려면 함수 또는 요소의 이름을 바꾸십시오.
<html>
<head>
<script>
function upload(){
alert("I am an alert box!");
}
</script>
</head>
<body>
<form enctype="multipart/form-data" method="post" onsubmit="return upload();">
<input type="file" name="file">
<input type="submit" name="upload2" value="Datei hochladen">
</form>
</body>
</html>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다