替换onclick

时间:2011-06-12 09:40:51

标签: javascript

我希望在点击电话代码文本时显示第二个提示范围hint2,当点击电话号码文本时,它显示第一个提示范围只能用JavaScript做????

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

1 个答案:

答案 0 :(得分:1)

如果默认隐藏提示span元素(使用display:none),您可以使用document.getElementById('hintId').style.display = "inline"显示它们。

您可能希望在文本字段的onfocus事件中执行此操作,否则当有人使用键盘导航到该字段时(例如使用Tab键),它不会被触发。

有关示例,请参阅this fiddle