2012-07-19 211 views
1

我有這樣的代碼:隱藏DIV點擊時只出它

<input id="i" type="text" value="value" /> 
<div id="u" style="border:solid 1px;width:140px;height:100px"></div> 
<p>thanks</p> 

我要讓#U隱藏和顯示當我點擊I路。 然後當我點擊#u它將被隱藏。 但如果我點擊#u什麼都沒有發生。 你能幫我嗎。 非常感謝

+0

到目前爲止你的努力是什麼? – Nemoden 2012-07-19 07:16:24

+0

你可以發佈你用來隱藏和顯示div的代碼嗎? – 2012-07-19 07:16:46

回答

0
$("#i").focus(function() { 
    //When the user clicks on #i then #u is shown 
    $("#u").show(); 
}): 

$("#u").blur(function() { 
    //When the user clicks out of #u then #u is hidden 
    $("#u").hide(); 
}): 
+0

請原諒downvote? OP詢問「i」何時關注,因爲它是輸入。然後當失去焦點隱藏「#u」 – Undefined 2012-07-19 07:17:20

+0

你錯了,我downvoted之前,然後你編輯,所以我刪除downvote – bugwheels94 2012-07-19 07:20:06

+0

@AnkitGautam好的謝謝:) – Undefined 2012-07-19 07:20:19