0

这是代码:

1)jQuery:

<script src="Scripts/jquery.tools.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    $(function() {
        // if the function argument is given to overlay,
        // it is assumed to be the onBeforeLoad event listener
        $("a[rel]").overlay({
            mask: 'gray',
            effect: 'apple',
            onBeforeLoad: function() {
                // grab wrapper element inside content
                var wrap = this.getOverlay().find(".contentWrap");
                // load the page specified in the trigger
                wrap.load(this.getTrigger().attr("href"));
            }
        });
        $("#target").keypress(function(event) {
            // F1 pressed
            if (event.keyCode == 112) {
                alert("Help");
            }
        });
    });
</script>

2)标记:

<!-- external page is given in the href attribute (as it should be) -->
<a href="WebForm1.aspx" rel="#overlay" style="text-decoration:none">
  <!-- remember that you can use any element inside the trigger -->
  <button type="button">Show external page in overlay</button>
</a>

<!-- another link. uses the same overlay -->
<a href="WebForm2.aspx" rel="#overlay" style="text-decoration:none">
  <button type="button">Show another page</button>
</a>

<!-- overlayed element -->
<div class="apple_overlay" id="overlay">
  <!-- the external content is loaded inside this tag -->
  <div class="contentWrap"></div>
</div>

我在页面上有 2 个按钮,当单击其中任何一个按钮时,会显示带有一些文本的漂亮灰色层。如果我按 F1 键,我也想做同样的事情,就像我们寻求帮助一样。在此示例中出现消息框,但需要替换为灰色层。怎么做?

4

2 回答 2

0

这样做

$("body").keypress(function(event){
if(event.which == 12){  // keycode 12 for F1
  //trigger on click event 
   $("#element").click();
  //or write your code here
  code
 }
});
于 2013-01-31T08:55:00.173 回答
0

做一个单独的函数:

function loadWrap (wrap) {
    var wrap = this.getOverlay().find(".contentWrap");

    // load the page specified in the trigger
    wrap.load(this.getTrigger().attr("href"));
}

然后在两个事件处理程序中调用此函数:

onBeforeLoad: function() {
    // grab wrapper element inside content
    loadWrap(this);
}

//////////////////

$("#target").keypress(function(event) {
    // F1 pressed
    if (event.keyCode == 112) {
        loadWrap($("a[rel]").first());
    }
});
于 2013-01-31T08:53:01.657 回答