jQuery Mobile面板open事件
jQuery Mobile是一个建立在jQuery之上的JavaScript库。它被用来创建快速响应的网站或网络应用,可以在手机、平板电脑和台式机等各种设备上访问。
在这篇文章中,我们将使用jQuery Mobile Panel open事件,该事件在面板完全打开后被触发。
回调参数:回调函数接受一个event类型的参数和一个UI对象。UI对象是空的,它只是为了与整个jQuery Mobile库的其他事件保持一致。
语法:
- 用指定的打开回调初始化面板。
$(".selector").panel({
open: function( event, ui ) {
// Your code here
}
});
- 将panelopen事件绑定到一个事件监听器上。
$(".selector").on( "panelopen", function( event, ui ) {} );
参数:它接受一个持有两个参数的回调函数。
- event。它接受事件类型值。
- ui。它接受对象类型的值。ui对象可以是空的,但为了与其他事件保持一致而使用。
CDN Links:
<link rel=”stylesheet” href=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css” />
<script src=”https://code.jquery.com/jquery-2.1.3.js”></script>
<script src=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js”></script>
例子:在下面的例子中,当面板的open事件被触发时,一个警报框被打开。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1">
<link rel="stylesheet" href=
"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src=
"https://code.jquery.com/jquery-2.1.3.js">
</script>
<script src=
"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js">
</script>
<script>
(document).ready(function () {
("#divID").panel({
open: function (event, ui) {
alert("Panel open event fired.");
}
});
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" >
<h1 style="color:green;">GeeksforGeeks</h1>
<h3>jQuery Mobile Panel open event</h3>
</div>
<div role="main" class="ui-content">
<center>
<a href="#divID">Open Panel</a>
</center>
</div>>
<div data-role="panel" id="divID">
<p>Panel Content</p>
</div>
</div>
</body>
</html>
输出:

极客教程