[英]JQuery Mobile HREF link not working with Javascript
I have a button that I want to open a panel. 我有一个要打开面板的按钮。 Unfortunately my javascript is getting in the way.
不幸的是,我的JavaScript成为了障碍。 It's a notifications center in the panel and in order to retrieve the notifications I have to put javascript in the href of the link....but its not opening the open.
它是面板中的通知中心,为了检索通知,我必须将javascript放在链接的href中。
I put tags where the problem is that say THIS IS WHERE THE PROBLEM LIES. 我将标签放在问题所在,说这是问题所在。
If I change the href to #myContent then it will open, but in order for the script to work I need to to be javascript in the href. 如果将href更改为#myContent,它将打开,但是为了使脚本正常工作,我需要在href中使用javascript。
Here's my code: 这是我的代码:
<? //PHP for getting username and database here ?>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
function toggleDiv(divId) {
$("#"+divId).toggle();
$(document).ready(function(){
$("#myContent").load("getnotes.php?name=<? echo $username; ?>");
});
}
</script>
<!-- BEGIN PAGE 1 -->
<div data-role="page" id="feed" data-add-back-btn="true">
<div data-role="panel" id="settingspanel" data-position="left" data-display="overlay">
<!--THIS IS THE LEFT PANEL-->
</div>
<div data-role="header" data-position="fixed" data-theme="c" data-tap-toggle="false" data-id="foo1" style="padding-top: 5px; border-bottom: 1px solid #eccfb3; padding-bottom: 5px;">
<a href="#settingspanel" data-role="button" data-iconpos="notext" class="icon-reorder icon-2x" style="background: none; margin-left: 20px;"></a>
<center><img src="images/logo_app_white.png" height="25px"></center>
<!--THIS IS WHERE THE PROBLEM LIES-->
<a href="javascript:toggleDiv('myContent');" data-role="button" data-iconpos="notext" class="icon-bell-alt icon-2x" style="background: none; margin-right: 20px;"></a><? echo $number; ?>
</div>
<div data-role="content">
<!--This is where the content of the page goes-->
</div>
<div data-role="footer" data-position="fixed" data-theme="c" data-tap-toggle="false" data-id="foo1" style="border-top: 1px solid #eccfb3; padding-top: 5px;">
<div data-role="navbar" style="background: #ce8339;">
<ul>
<li><a href="#feed" class="icon-tasks icon-2x" data-ajax="false">My Feed</a></li>
<li><a href="#submit" class="icon-upload icon-2x" data-ajax="false">Submit</a></li>
<li><a href="#browse" class="icon-search icon-2x" data-ajax="false">Browse</a></li>
<li><a href="myprojects.php" class="icon-folder-open-alt icon-2x" data-ajax="false">Projects</a></li>
</ul>
</div>
<!-- /navbar -->
</div>
<div data-role="panel" id="myContent" data-position="right" data-display="overlay">
<!--THIS IS THE PANEL-->
</div>
</div>
<!-- END PAGE 1 -->
Why isn't the panel opening and how can I fix the issue. 面板为什么没有打开,如何解决该问题。
Why put javascript in the 'href' tag and not in 'onclick'? 为什么将javascript放在“ href”标记中而不放在“ onclick”中? My guess is
我的猜测是
<a href="javascript:void(0);" onclick="toggleDiv('myContent');">
will fix the issue. 将解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.