2011-06-12 67 views
1

我希望當點擊電話代碼文本顯示它的第二提示跨度HINT2當點擊電話號碼的文本顯示其第一個暗示跨度是可能的只有JavaScript做????替換的onclick

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Javascript Change Div InnerHTM</title> 
    <link type="text/css" rel="stylesheet" href="pasha_css/hint.css"></link> 
    <script type="text/javascript" src="pasha_js/hint.js"></script> 
    <link href="pasha_css/main.css" type="text/css" rel="stylesheet" /> 
    </head> 
    <body> 
    <div id="form-item7" class="form-profile"> 
    <label class="form-phone">Phone:</label> 
    <input type="text" name="Phone_code" value="03" class="form-text phonecode " onclick="this.value=''" onselect="this.value=''"></input> 
    <input type="text" name="phone" value="4567890" 
     class="form-text phone" onclick="this.value='';" onselect="this.value=''"></input> 
    <span id="hint1" class="hint">Use Text only please! 
    <span class="hint-pointer">&nbsp;</span> 
    </span> 
    <span id="hint2" class="hint">enter code! 
    <span class="hint-pointer">&nbsp;</span> 
    </span> 
     </div> 
    </body> 
    </html> 
+0

使用jQuery,只有它的JavaScript。 :P – 2011-06-12 09:45:32

回答

1

如果提示span元素默認是隱藏的(使用display:none),你可以向他們展示與document.getElementById('hintId').style.display = "inline"

您可能希望在文本字段的onfocus事件中執行此操作,否則當某人用鍵盤導航到該字段時(例如使用tab鍵),它不會被觸發。

爲一個例子見this fiddle