简体   繁体   English

如何从值中调用函数

[英]How to call function from value

I'm trying insert this value in text field in my app. 我正在尝试在应用程序的文本字段中插入此值。 It should look like this: player1@enigmania.cz where 1 is random number between 1 and 100. Problem is that i cannot find anywhere on web or documentation how to call function from within value. 它应该看起来像这样:player1@enigmania.cz其中1是1到100之间的随机数。问题是我无法在Web或文档中的任何地方找到如何从值内调用函数。 The part of code looks like this: 代码部分如下所示:

function rand(min, max) { return Math.floor(Math.random() * 101);
}

function loginNoreg(e) {
$.txtName.value="player"+"rand"+"@enigmania.cz";

This gives just playerrand@enigmania.cz and not player1@enigmania.cz as I need. 这仅提供了playerrand@enigmania.cz而不是我需要的player1@enigmania.cz。 Thanks for any ideas how to do this. 感谢您提出任何建议。

Just call the function inline, without quotes. 只需内联调用函数,不带引号。 With quotes it is just a string. 带引号的只是一个字符串。

$.txtName.value= "player" + rand() + "@enigmania.cz";

In order to use your min/max you want, provide the values in the line above and adjust your function like this 为了使用所需的最小/最大值,请在上面的行中提供值,并像这样调整功能

function rand(min, max){
    return min + Math.floor(Math.random() * (max-min+1));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM