2017-04-12 58 views
0

回覆按鈕如何顯示/隱藏輸入類型:文本時,按鈕是點擊

<div id="replybutton" class="btn4 like" style="margin-top:-25px;margin-left:-10px;"> 
    <span class="btn reply" id="replyb">Reply</span> 
</div> 

輸入字段

<div class="col-lg-12" style="background:#eff9c7;"> 
    <input type="text" id="reply" class="form-control pull-right" style="width:88%;height:25px;margin-top:-10px;" placeholder="Write a reply..." /> 
</div> 

所以這裏什麼IM想說明的是,當我重新加載頁面的輸入字段應該隱藏,當我點擊答覆按鈕時,它會顯示..當我再次單擊它將隱藏..我試圖使用toggle() jquery上的作品,但問題是,如果我重新加載頁面的按鈕是可見這不是正確的事情..我甚至試圖使用.show().hide(),但它似乎很想失去一些東西,所以它不起作用。有沒有什麼辦法可以讓它發生,當我重新加載頁面的輸入字段應該隱藏..

+0

使用CSS display:none或使用的cookie,如果設置cookie,然後不顯示其他節目。 –

+0

'$(函數(){ $( '#回覆'),隱藏(); });' '$( 「#replyb」)。在( '點擊',函數(){$ ( 「#reply」).toggle(); });' – Gaurav

+0

使用css display:none,當頁面加載時隱藏.... –

回答

0

使用下面的代碼片段:

記住初始狀態應該被隱藏style="display:none;"

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="replybutton" class="btn4 like"> 
 
<span class="btn reply" id="replyb" onClick="$('#reply').toggle();">Reply</span> 
 
</div> 
 

 
    <input type="text" id="reply" class="form-control pull-right" placeholder="Write a reply..." style="display:none;"/>

您也可以使用點擊監聽器的方法:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <div id="replybutton" class="btn4 like"> 
 
    <span class="btn reply" id="replyb">Reply</span> 
 
    </div> 
 
     <input type="text" id="reply" class="form-control pull-right" placeholder="Write a reply..." style="display:none;"/> 
 
     
 
<script> 
 
$(document).ready(function(){ 
 
    $('#replyb').click(function(){ 
 
    $('#reply').toggle(); 
 
    }); 
 
}); 
 
</script>

0

$('#replybutton').click(function() { 
 
    $('#reply').toggle() 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="replybutton" class="btn4 like" style=""> 
 
    <span class="btn reply" id="replyb">Reply</span> 
 
</div> 
 
<div class="col-lg-12" style="background:#eff9c7;"> 
 
    <input type="text" id="reply" class="form-control pull-right" style="width:88%;height:25px;margin-top:0px;" placeholder="Write a reply..." hidden /> 
 
</div>

0

您可以使用:

style='visibility:hidden'style='display:none」。

$('#replyb').click(function() { 
    $('#reply').toggle() 
}) 
0

嘗試使用這樣的:

<script> 
$(document).ready(function(){ 
    $('#replyb').click(function(){ 
    $('#reply').toggle(); 
    }); 
}); 
</script> 
相關問題