這是我的HTML代碼如何我可以顯示和隱藏輸入標籤,而焦點進出
<label for="first_name">First Name</label>
<input class="w3-input" type="text" name="first_name" id="first_name">
<label for="last_name">Last Name</label>
<input class="w3-input" type="text" name="last_name" id="last_name">
,而我輸入點擊我需要隱藏的標籤,以得到結果我創建下面的jQuery代碼,但不加工。
$(document).ready(function(){
$(".w3-input").click(function(){
var item_select = this.id; //getting id of clicked item
$(item_select).focusin(function(){
$(this).prev("label").hide(); //hide label of clicked item
});
$(item_select).focusout(function(){
$(this).prev("label").show();
});
});
});
有什麼錯我的代碼中的任何一個幫助我嗎?如果你還沒有點擊輸入刪除click事件的作品確定