이 코드에 대해 친절하게 도와 주시겠습니까? 버튼을 클릭하면 이미지 목록을 채우려 고합니다.은 screenShotsList.txt
다음과 같은 파일 이름으로 구성됩니다.
out1.png
out2.png
out3.png
out4.png
out5.png
out6.png
out7.png
out8.png
지금 내 문제는 내 배열을 이미지 그룹으로 표시하는 구문을 idk하고 버튼을 클릭하면 코드가 작동하지 않는다는 것입니다.
지금까지 가지고있는 코드입니다 ..
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$("button").click(function(){
var file = "C:/newbots/ctfuPoster/data/screenShotsList.txt";
function getFile(){
$.get(file,function(txt){
var lines = txt.responseText.split("\n");
for (var i = 0, len = lines.length; i < len; i++) {
// Equivalent: $(document.createElement('img'))
var img = $('<img id="dynamic">');
img.attr('src', lines[i]);
img.appendTo('#imagediv');
}
});
}
});
</script>
미리 감사드립니다
이 예에서는 약간의 스크립트가있는 간단한 html 페이지가 있습니다.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow" />
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
$.ajax({
url : "screen.TXT",
dataType: "text",
success : function (data) {
console.log(data)
var lines = data.split(",")
for (var i = 0; i < lines.length; i++) {
var img = $('<img class="dynamic">');
img.attr('src', lines[i]);
img.appendTo('#imageDiv');
}
}
});
});
})
</script>
</head>
<body>
<div id="imageDiv"></div>
<input value="clickMe" type="button" id="button">
</body>
</html>
스크립트 작업을 위해 다음과 같은 구조와 이름이 screen.txt 인 간단한 텍스트 파일을 만들었습니다.
이 텍스트 파일에는 lorempixel.com의 사진에 대한 링크가 html 페이지
screen.txt 파일 과 동일한 수준에 있어야합니다.
http://lorempixel.com/output/abstract-q-c-300-300-7.jpg,
http://lorempixel.com/output/abstract-q-c-300-300-9.jpg,
http://lorempixel.com/output/abstract-q-c-300-300-2.jpg
온라인 작업 예제를 보려면 이 페이지 를 방문하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다