好的,这是交易:
我找到了这段代码,我想将其用于生成随机引号的按钮。现在它被设置为只做 10 个字母的单词。我看到可以更改该值,以便文本框可以容纳更大的字符结果。但是,有没有办法做到这一点,以便在 onclick 事件之后根据它吐出的引号的字符长度动态生成文本框的大小?如果是这样,有没有办法让它垂直延伸而不仅仅是水平延伸?当我现在把它变大,以容纳大约 150 个字符时,它只是跑出页面。我是 JS 的新手,所以任何帮助或指导将不胜感激。
代码:
<!DOCTYPE html>
<html>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Use the following variable to specify
// the number of random words
var NumberOfWords = 28
var words = new BuildArray(NumberOfWords)
// Use the following variables to
// define your random words:
words[1] = "czarevitch"
words[2] = "brightwork"
words[3] = "verkrampte"
words[4] = "protectrix"
words[5] = "nudibranch"
words[6] = "grandchild"
words[7] = "newfangled"
words[8] = "flugelhorn"
words[9] = "mythologer"
words[10] = "pluperfect"
words[11] = "jellygraph"
words[12] = "quickthorn"
words[13] = "rottweiler"
words[14] = "technician"
words[15] = "cowpuncher"
words[16] = "middlebrow"
words[17] = "jackhammer"
words[18] = "triphthong"
words[19] = "wunderkind"
words[20] = "dazzlement"
words[21] = "jabberwock"
words[22] = "witchcraft"
words[23] = "pawnbroker"
words[24] = "thumbprint"
words[25] = "motorcycle"
words[26] = "cryptogram"
words[27] = "torchlight"
words[28] = "bankruptcy"
function BuildArray(size){
this.length = size
for (var i = 1; i <= size; i++){
this[i] = null}
return this
}
function PickRandomWord(frm) {
// Generate a random number between 1 and NumberOfWords
var rnd = Math.ceil(Math.random() * NumberOfWords)
// Display the word inside the text box
frm.WordBox.value = words[rnd]
}
//-->
</SCRIPT>
<body>
<FORM NAME="WordForm">
<INPUT TYPE=TEXT SIZE=10 NAME="WordBox"><BR>
<INPUT TYPE=BUTTON onClick="PickRandomWord(document.WordForm)"
VALUE="Refresh">
</FORM>
</body>
</html>