我有一些单选按钮的设置是这样的:当用户点击jQueryUI单选按钮时,如何停止浏览器视口移动到页面顶部?
<div id="typeRadios">
<input id="note_notetype_note1" name="note[notetype]" type="radio" value="note1" /><label for="note_notetype_note1">note1</label>
<input id="note_notetype_note2" name="note[notetype]" type="radio" value="note2" /><label for="note_notetype_note2">note2</label>
</div>
那我变成jQueryUI的按钮,像这样:
$("#typeRadios").buttonset();
这是生成的HTML:
<input type="radio" value="note1" name="note[notetype]" id="note_notetype_note1" class="ui-helper-hidden-accessible">
<label for="note_notetype_note1" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button" aria-disabled="false"><span class="ui-button-text">note1</span></label>
<input type="radio" value="note2" name="note[notetype]" id="note_notetype_note2" class="ui-helper-hidden-accessible">
<label for="note_notetype_note2" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button" aria-disabled="false"><span class="ui-button-text">note2</span></label>
按钮工作,但每当我点击一个,浏览器视图端口就会返回到页面顶部,与点击<a href="#">link</a>
链接时发生的情况相同。
我正在使用jQuery 1.4.2和jQueryUI 1.8.7。我怎样才能防止这种行为?谢谢阅读。
编辑:<a href="#">link</a>
部分丢失。
当您隐藏单选按钮时,它会将它们从屏幕移到页面的顶部。这就是为什么当浏览器被选中时跳到顶端的原因。尝试添加位置:相对于您的div'typeRadios' - 这将它们本地化到屏幕的该区域。 – 2013-05-08 12:34:46