-1

#buttonSaveAreaページの読み込み時に要素を非表示にし、要素を表示したい#buttonSaveShower。をクリックすると#buttonSaveShower、非表示になり、表示される#buttonSaveAreaはずです。

問題は、$(document).ready何度も呼び出されることです。それを回避する方法は?また、JavaScript が無効になっている場合は#buttonSaveArea、最初から表示されるようにしたいと考えています。

$(document).ready(function(){
  $("#buttonSaveArea").hide();

  $("#buttonSaveShower").click(function(){
    $("#buttonSaveArea").fadeIn();
    $("#buttonSaveShower").hide();
  });
});


<!------ The element that should show the button below ---------------->
<div class="button" id="buttonSaveShower" style="clear:both; margin-top:15px;">
    <a href="" style="width:50px !important;"> edytuj </a>
</div>

<!------ Button: save ---------------->
<div class="fbCenter" id="buttonSaveArea">
    <input type="submit" value="Zapisz" class="formButton"
       onmouseover="this.className+=' pressed'"
       onmouseout="this.className=this.className.replace(' pressed', '')"
    />
</div>
4

2 に答える 2

3

を使用して、アンカー タグによるページのリロードを停止する必要があります。event.preventDefault()

$(document).ready(function(){
  $("#buttonSaveArea").hide();

  $("#buttonSaveShower").click(function(event){
    event.preventDefault();
    $("#buttonSaveArea").fadeIn();
    $("#buttonSaveShower").hide();
  });
});

また、非表示でページをロードしたい場合#buttonSaveArea。デフォルトでcssを使用して非表示にする必要があります

#buttonSaveArea{
   display: none;
}
于 2013-04-28T06:28:38.707 に答える
0

交換<a href="">して助かり<a href="#">ました。ご提案いただきありがとうございます。

于 2013-04-28T06:40:14.043 に答える