與輸入相鄰的按鈕。該按鈕在默認情況下處於隱藏狀態,並且在輸入獲得焦點時可見,並且如果輸入失去焦點,則會再次隱藏該按鈕。
我寫了一個代碼來實現這一點。但問題是按鈕的事件沒有被觸發,因爲它在輸入失去焦點時被隱藏。
我沒有得到任何想法實現這一點。可以有人幫助我。
下面是代碼
<html>
<head>
<style>
.icon{
visibility:hidden;
}
</style>
</head>
<body>
<input type="text" onFocus="onOver('f4_1')" onBlur="onOut('f4_1')"/>
<input type="button" class="icon" value="?" id="f4_1" onClick="alert('hi..')"/>
<script>
function onOver(f4Id){
document.getElementById(f4Id).style.visibility = "visible";
}
function onOut(f4Id){
document.getElementById(f4Id).style.visibility="hidden";
}
</script>
</body>
</html>
注:使用純JavaScript來實現。不要使用任何jQuery。
謝謝。
聽起來像功課。 –
抱歉...輸入錯誤..問題編輯爲 –