我怎么能叫“STOP()”在HTML?
这是downloadFile2内()。
例如JS
function download() {
var req = request({
method: 'GET',
uri: url
});
var out = fs.createWriteStream(path);
req.pipe(out);
function stop(){
req.pause();
}
req.on('response', function(data) {
});
req.on('data', function(chunk) {
stop();//I want to execute this method at html .
});
}
HTML
<tr><td><a class="checkBtn" onclick="downloadFile2(event)">download</a></td><td><a class="checkBtn" onclick="downloadFile2.innerfunc();" value="ACTION">stop~!!!</a></td></tr>
您可以使用events
,呼吁stop
从功能HTML
。
const events = require('events');
var EventEmitter = new events.EventEmitter();
function download() {
var req = request({
method: 'GET',
uri: url
});
var out = fs.createWriteStream(path);
req.pipe(out);
EventEmitter.on("stop",function(){
req.pause();
})
req.on('response', function (data) {
});
req.on('data', function (chunk) {
stop();//I want to execute this method at html .
});
}
function stop() {
EventEmitter.emit("stop");
}
但要确保download
功能被称为前stop
功能。
你可以通过这个调用另一个内部功能
function download() {
var req = request({
method: 'GET',
uri: url
});
var out = fs.createWriteStream(path);
req.pipe(out);
this.stop = function stop(){
req.pause();
}
req.on('response', function(data) {
});
req.on('data', function(chunk) {
stop();//I want to execute this method at html .
});
}
然后调用此子功能
<td><a class="checkBtn" onclick="(new download()).stop();" value="ACTION">stop~!!!</a></td>