答案 0 :(得分:0)
这是答案。我改变了东西并制作了对象,然后将它们导出到html文件中。
var zipArry = [];
var zipResult = [];
var aniArry = [];
var aniResult = [];
var blah = {
ziplist: function zipList(callback) {
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('.Text1.txt')
});
lineReader.on('line', function (line) {
zipArry.push(line);
});
lineReader.on('close', function (line) {
var Ncount = 0;
for(var x = 0; x < zipArry.length; x++){
zipResult.push(zipArry[x]);
}
callback(zipResult);
});
}
anilist: function aniList(callback) {
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('./text2.txt')
});
lineReader.on('line', function (line) {
aniArry.push(line);
});
lineReader.on('close', function (line) {
var Ncount = 0;
for(var x = 0; x < aniArry.length; x++){
aniResult.push(aniArry[x]);
}
callback(aniResult);
});
}
};
module.exports = blah;
在html文件中
var blah = require('./apps2.js');
Blah.ziplist(function(zipResult){
var select = document.getElementById("zip");
for (var i = 0; i < zipResult.length; i++){
var el = document.createElement('option');
var opt = zipResult[i];
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
});
Blah.anilist(function(aniResult){
var select = document.getElementById("ani");
for (var i = 0; i < aniResult.length; i++){
var el = document.createElement('option');
var opt = aniResult[i];
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
});