Original link: https://www.mqllin.cn/archives/191.html
1. Random number (TS script)
The existing random number method in Laya is based on the value of 0~1. After expansion, any positive integer interval, the code is as follows
“`
/**
* random number
* @param min minimum number
* @param max maximum number
*/
private randomNumber(min: any, max: any): any
{
return Math. floor(
parseInt(
Math.random() * (max – min + 1) + min, 10)
);
}
“`
2. Copy to pasteboard (JS script)
Copy the text on the mouse or mobile phone to the clipboard, the code is as follows
“`
CopyUrl: function (url) {
const t = document.createElement(‘textarea’);
t.value = url;
t.style.visibility = true;
// join the document stream
document.body.appendChild(t);
// Select the content of the textarea and copy it to the clipboard
t. select();
document.execCommand(‘copy’);
// remove hidden textarea
t. parentElement. removeChild(t);
}
“`
This article is transferred from: https://www.mqllin.cn/archives/191.html
This site is only for collection, and the copyright belongs to the original author.