开发者

Using jquery to conditionally display spans causes them to redisplay at wrong positions

开发者 https://www.devze.com 2023-01-05 18:19 出处:网络
The code is : $(\"#radioGroup\").click(function(){ $(\"#groupSpan\").css(\"display\", \"block\"); $(\"#advisorSpan\").css(\"display\", \"none\");

The code is :

$("#radioGroup").click(function()  {
    $("#groupSpan").css("display", "block");
    $("#advisorSpan").css("display", "none");
});

and for second button of radio group:

$("#radioAdvisor").click(function()  { 
  $("#groupSpan").css("display", "none");
  $("#advisorSpan").css("display", "block");
});

this works fine, well almost. If you scroll between clicking radio buttons, the span is displayed in the inccorect position - basically where it shoudl have been before scroll - looks well strange jsut appears ove开发者_运维技巧r completely unrelated elements.

Please help?


I would suggest using the shortcut methods. They usually display better.

$("#radioGroup").click(function()  {
    $("#groupSpan").show();
    $("#advisorSpan").hide();
});

$("#radioAdvisor").click(function()  { 
  $("#groupSpan").hide();
  $("#advisorSpan").show();
});


$("#radioGroup").click(function()  {
    $("#groupSpan").css("display", "inline");
    $("#advisorSpan").css("display", "none");
});

$("#radioAdvisor").click(function()  { 
  $("#groupSpan").css("display", "none");
  $("#advisorSpan").css("display", "inline");
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号