前:
xxx.txt
结果: 1. Js数组应单独存储每一行。
答案 0 :(得分:1)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
var file_path = "other.txt";
var output_array = new Array(); // __output array
var arr = 0;
var line = "";
$(document).ready(function(){
$.get(file_path, function(data) {
for(i = 0; i < data.length; i++){
if(data[i] == '\n' || i == ( data.length - 1 )){
output_array[arr] = line; arr++; line = "";
continue;
}
line = line + data[i];
} // __creating lines
// __testing it
for(i = 0; i < output_array.length; i++) alert(output_array[i]); // __line for testing purpuse
}, 'text');
}); // __document.ready
</script>
</head>
<body>
</body>
</html>
// __在我的工作:),谢谢