好的,这是交易:
我发现这段代码我想用于生成随机引号的按钮。现在它被设置为只做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>
答案 0 :(得分:0)
这听起来像你在css中会做的事情。尝试这样的事情。
<FORM NAME="WordForm" style="max-width:50px; overflow-y: scroll;">