我正在创建一个imacros脚本来选择html select元素中的随机选项。
像这样:
mcr +="TAG POS=1 TYPE=SELECT ... CONTENT=#"+opcionAleatoria(12)+ '\n';
opcionAleatoria()是抓取随机数的函数:
总计是选择内的选项总数。
function opcionAleatoria(total) {
return Math.floor(Math.random() * total) + 1;
}
我希望现在能够将总计(选择中的选项)作为参数传递给函数。
为什么吗
有两个原因:
我尝试传递 document.form.select_id.options.length ,但由于未定义imacros 文档,因此无法正常工作。
您对我如何处理案件有什么想法吗?
答案 0 :(得分:2)
尝试像这样修改你的表达式:
var total = window.document.forms[0].select_id.options.length;
如果上面提到的方法不起作用,那么这里更可靠:
iimPlay("CODE:TAG POS=1 TYPE=SELECT ... EXTRACT=TXTALL");
var total = iimGetExtract().split("[OPTION]").length;
(我想您使用' iMacros for Firefox'及其脚本界面。)