嗨我想製作一個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>`
其看來,我的代碼永遠不會到達隨機函數,我不知道我在這裏做錯了什麼。
你確定'隨機()'函數沒有運行?通過在函數的開頭添加一個alert('runs');'或類似的東西來測試它。 – 2013-04-05 06:55:59
我試過了,沒有信息:S – laitha0 2013-04-05 06:58:44