点击链接时滚动到页面底部

Scrolling to bottom of the page when link clicked?

本文关键字:底部 滚动 链接      更新时间:2023-09-26

当链接被点击时,我打开jQuery对话框。对话框打开良好,但页面向下滚动到页面,所以我不能看到对话框,直到我向上滚动。我怎样才能避免这种情况呢?

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
            jQuery("#waitDialog").dialog({
            autoOpen: false,
            modal: true,
            height: 375,
            position: 'center',
            width: 400,
            draggable: true,                
            closeOnEscape: false,
            open: function (type, data) {
                $(".ui-dialog-titlebar-close").hide();
                $(this).parent().appendTo("form");
            }
        });
    });
    function showDialog(id) {
            $('#' + id).dialog("open");     
    }
</script>
 <div id="waitDialog" style="display:none; cursor: default">        
    <table  class="ms-authoringcontrols"  style="border-top:1px black solid; border:1px black solid; height:70px "  >
    <tbody>
          <tr>
        <td class="ms-sectionheader ms-rightAlign">
            Please wait.
        </td>
          </tr>
    </tbody>
    </table>
  </div>
<map name="Map">
  <area shape="rect" coords="225,16,287,33" href="/_layouts/MyAlerts.aspx" onclick="javascript:showDialog('waitDialog');"  alt="My Alerts">
 </map>

您的链接的.click()事件应该是return false,这样它就不会被跟随,导致页面跳转到您的id元素

$('a').click(function() {
  showDialog($(this).attr('href'))
  return false;
});

听起来你有锚标记的问题。代替href="/_layouts/MyAlerts.aspx"

可以使用:

onclick='window.location = "/_layouts/MyAlerts.aspx";