1

こんにちは、テキスト ボックスにランダムなテキストを入力できる MVC アプリケーションを作成しようとしています。この単純なスクリプトを作成して、配列からランダムな単語を取得しました

<script type="text/javascript">
function random() {
    var adjective = new Array('quick', 'pleasant', 'successive', 'interim',
    'optimistic', 'sensitive', 'temporary', 'reminiscent', 'drooly', 'muddy',
    'maddening', 'ceaseless', 'bawdy', 'earthy', 'european', 'aboard', 
    'innovative', 'broad', 'smelly', 'mad', 'reduced', 'plucky', 'glib', 'liable',
    'ratty', 'venomous', 'chivalrous', 'wide', 'moral', 'scary');
    rdm = Math.floor(Math.random() * adjective.length);
    document.getElementById("adj1").nodeValue = adjective[rdm];
}

そして、私は次のようなものを持っています

`

<div class="editor-label">
    @Html.LabelFor(model => model.adj1)
    <button type="button" title="Random" id="1" onclick="random()">
        <img src="../../Content/themes/base/images/random.png" alt="" />
    </button>
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.adj1) 
    @Html.ValidationMessageFor(model => model.adj1) 
</div>`

私のコードがランダム関数に到達しないようです。ここで何が間違っているのかわかりません。

4

1 に答える 1

0

これを試して:

document.getElementById("adj1").value = adjective[rdm];
于 2013-04-05T06:53:08.970 に答える