2013-04-05 4 views
1

안녕하세요, 텍스트 상자에 임의의 텍스트를 입력 할 수있는 MVC 응용 프로그램을 만들려고합니다. 나는 배열에서텍스트 상자에 임의의 텍스트 삽입 cshtml javascript MVC3

<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>` 

같은이 내 코드 결코 무작위 함수에 도달하면, 내가 여기서 잘못하고있는 것이 확실하지 않습니다.

+0

당신은'랜덤() '함수가 실행되고 있지 확실합니까? 함수의 시작 부분에'alert ('runs'); 또는 비슷한 것을 추가하여 이것을 테스트하십시오. –

+0

나는 그 메시지를 보지 않았다 : S – laitha0

답변

0

이 시도 :

document.getElementById("adj1").value = adjective[rdm]; 
+0

동일한 출력, 아무런 반응이 없다. – laitha0

+0

당신의 해결책이 고정되어 있지 않다. 감사합니다 – laitha0

+0

@ user2247823 당신은 오신 것을 환영합니다 :) – karaxuna

관련 문제