2010-04-29 123 views
0

例如:如何在不失焦點的情況下更換內容?

<input type="text" name="test" onChange="document.formname.test.value=.document.formname.test.value.replace('something','something else')" /> 

替換功能的作品,但它失去專注於每一個變化

你怎麼讓它不失去焦點?

我想要做的就是讓這個特定的文本立即用新的文本替換它的類型時,但你可以繼續輸入

回答

0

如果你想保持關注那些輸入嘗試:

onChange="document.formname.test.value=.document.formname.test.value.replace('something','something else'); document.formname.test.focus();" 
2

簡短的回答:document.formname.test.focus();

<input type="text" name="test" onChange="document.formname.test.value=document.formname.test.value.replace('something','something else'); document.formname.test.focus();" /> 
0

請不要使用onchange屬性JavaScript的不應該是在HTML標記無盡的絕對必要。相反,請將您的腳本包含在頁面主體的末尾。

<body> 
    some content... 
    <script src="path to your script" type="text/javascript"></script> 
</body> 
+1

這意味着用戶可以在設置「onchange」之前與表單元素進行交互,以防止腳本行爲無法工作,直到整個頁面加載完畢。此外,這不能回答這個問題。 – 2010-04-29 21:57:51

相關問題