여기에 거래가 있습니다. 나는 그것의 헤더에 내부 JS 파일에 링크 index.php 있어요. index.php에는 다음과 같은 다른 .php 파일이 포함되어 있습니다. + 파일 추가. addFile()은 외부 JS 파일에 정의 된 Javascript 함수입니다.자바 스크립트 함수 호출 PHP 파일 포함
이렇게하면 아무런 일도 일어나지 않습니다. 포함 된 PHP는 JS 함수를 "보지 못합니다". 포함 된 PHP에서 JS를 캡슐화하면 모든 작업이 가능합니다. 하지만 나는 그런 식으로하고 싶지 않습니다.
아이디어가 있으십니까?
는 편집 :
여기 소스
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Archie</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="/screen.css" type="text/css" media="screen"/>
<script src="/lib/js/archie.js" type="text/javascript"></script>
</head>
<body>
...
...
//included php starts here
<form action="/lib/course.php" method="post">
<fieldset>
<div id="addFileLocation"></div>
<a href="#" onClick="addFile()">+ add file</a>
<input type="hidden" id="addFileCount" value="0"/>
</fieldset>
</form>
//ends here
...
...
</body>
</html>
와 JS의 :
<script type="text/javascript">
//Dynamically add form fields
//add file browser
function addFile() {
var location = document.getElementById('addFileLocation');
var num = document.getElementById('addFileCount');
var newnum = (document.getElementById('addFileCount').value -1)+ 2;
num.value = newnum;
var newname = 'addFile_'+newnum;
var newelement = document.createElement('input');
newelement.setAttribute('name',newname);
newelement.setAttribute('type','file');
location.appendChild(newelement);
}
</script>
어, 우리는 내가 믿는 출처를보아야 할 것입니다. – Robus