![](/img/trans.png)
[英]Problem with a function taken as a function parameter that takes AJAX as its own parameter
[英]Recursive function not incremeanting its own parameter
var documentURLs = ["maca.pdf", "maca2.pdf"] function printDocuments(index){ if(index > documentURLs.length){ return; } else { printJS({ printable: documentURLs[index], type: 'pdf', onPrintDialogClose: function () { console.log(index); printDocuments(index++) } }) } }
<button type="button" onclick="printDocuments(0)">Print</button>
这不会增加索引,始终打印第一个文档并且不会停止
它的行为与其应有的完全一样。 如果你想用下一个索引调用printDocuments
,你应该使用printDocument(++index)
或只使用printDocument(index+1)
,因为它是最容易混淆的。 i++
返回的电流值i
,然后添加1 ++i
第一加1点,并返回该增加的值(因此i+1
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.