2015-10-15 129 views
5

我有一个小任务查看器与面板,您可以创建一个任务,无论如何,我遇到的问题是,当你在移动设备上,并向下滚动面板,它会回到顶部,所以你需要再次向下滚动,以便能够点击你想要的输入,当你填写完(或不是)输入,并尝试点击后退按钮来解除键盘它会再次回到顶部。为什么我的面板在移动设备上滚动? jQueryMobile

我试图使用.focus但它忽略它。

为什么会发生?我该如何解决它?任何帮助真诚赞赏。

点击加号按钮,打开面板

PS:我清理代码重点考虑的问题

我的代码:

#header { 
 
    background-color: #72a9dc; 
 
    text-shadow: 0 0 3px #000; 
 
    color: white; 
 
} 
 
.code { 
 
    background-color: #b4d0ec; 
 
    text-shadow: 0 0 1px #fff; 
 
    border-radius: 3px; 
 
    width: 30px; 
 
    text-align: center; 
 
    float: left; 
 
} 
 
.label { 
 
    margin-left: 10px; 
 
    text-align: center; 
 
    float: left; 
 
} 
 
.date { 
 
    float: right; 
 
    border-radius: 3px; 
 
    border: 1px solid #000; 
 
    width: 100px; 
 
    height: 20px; 
 
    text-align: center; 
 
    text-shadow: 0 0 0 #fff; 
 
    color: black; 
 
} 
 
.detail { 
 
    font-size: 20px; 
 
    color: #72a9dc; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> 
 
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> 
 
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" /> 
 
</head> 
 

 
<body> 
 
    <div id="header" data-role="header" style="overflow:hidden;" data-position="fixed" data-tap-toggle="false"> 
 
    <h1>Title</h1> 
 
    <a onclick="onTop();" data-icon="search" data-iconpos="notext">Search</a> 
 
    <a onclick="newTask();" id="newTask" href="#add-form" data-icon="plus" data-iconpos="notext">Add</a> 
 
    </div> 
 

 
    <div role="main" class="ui-content jqm-content jqm-fullwidth"> 
 

 
    <form class="ui-filterable" id="search"> 
 
     <input id="rich-autocomplete-input" data-type="search" placeholder="Search. . ."> 
 
    </form> 
 

 
    <ul id="list" data-role="listview" data-filter="true" data-inset="true" data-input="#rich-autocomplete-input"> 
 
    </ul> 
 

 
    </div> 
 

 
    <div data-role="panel" data-position="right" data-display="reveal" data-theme="a" id="add-form"> 
 
    <form class="userform"> 
 
     <h2 id="myTitle"></h2> 
 
     <label>Code:</label> 
 
     <input type="number" id="code" min="1" value="" data-clear-btn="false" data-mini="true"> 
 
     <label>Label:</label> 
 
     <input type="text" id="label" maxlength="20" value="" data-clear-btn="true" autocomplete="off" data-mini="true"> 
 
     <label>Date:</label> 
 
     <input type="date" id="date" value="" data-clear-btn="true" data-mini="true"> 
 
     <label>Code:</label> 
 
     <input type="number" id="code" min="1" value="" data-clear-btn="false" data-mini="true"> 
 
     <label>Label:</label> 
 
     <input type="text" id="label" maxlength="20" value="" data-clear-btn="true" autocomplete="off" data-mini="true"> 
 
     <label>Date:</label> 
 
     <input type="date" id="date" value="" data-clear-btn="true" data-mini="true"> 
 

 
     <label>Code:</label> 
 
     <input type="number" id="code" min="1" value="" data-clear-btn="false" data-mini="true"> 
 
     <label>Label:</label> 
 
     <input type="text" id="label" maxlength="20" value="" data-clear-btn="true" autocomplete="off" data-mini="true"> 
 
     <label>Date:</label> 
 
     <input type="date" id="date" value="" data-clear-btn="true" data-mini="true"> 
 

 
     <label>Code:</label> 
 
     <input type="number" id="code" min="1" value="" data-clear-btn="false" data-mini="true"> 
 
     <label>Label:</label> 
 
     <input type="text" id="label" maxlength="20" value="" data-clear-btn="true" autocomplete="off" data-mini="true"> 
 
     <label>Date:</label> 
 
     <input type="date" id="date" value="" data-clear-btn="true" data-mini="true"> 
 

 
     <label>Code:</label> 
 
     <input type="number" id="code" min="1" value="" data-clear-btn="false" data-mini="true"> 
 
     <label>Label:</label> 
 
     <input type="text" id="label" maxlength="20" value="" data-clear-btn="true" autocomplete="off" data-mini="true"> 
 
     <label>Date:</label> 
 
     <input type="date" id="date" value="" data-clear-btn="true" data-mini="true"> 
 

 
     <div class="ui-grid-a"> 
 
     <div class="ui-block-a"><a href="#" data-rel="close" class="ui-btn ui-shadow ui-corner-all ui-btn-b ui-mini">Cancel</a> 
 
     </div> 
 
     <div class="ui-block-b"><a href="#" data-rel="close" class="ui-btn ui-shadow ui-corner-all ui-btn-a ui-mini" onclick="addTask();">Save</a> 
 
     </div> 
 
     </div> 
 
    </form> 
 
    </div> 
 
</body> 
 

 
</html>

回答

1

而不是使用href="#",它可以导致页面实际上转到上面,因为#是一个有效的链接,您可以(也应该)使用href="javascript:void(null);",它只是一个空的javascript函数,可以确保您的按钮不会做任何其他操作比它应该做的更多。

希望有所帮助。

+0

谢谢你提供的答案,我会尝试一下,然后我会回来:) +1 – Kyle

+0

没问题,它工作? –

+0

哦该死的,是的它的工作,我忘记标记它,我很抱歉,谢谢你提醒我。我使用不同的方法修复了它,但你的回答也起作用 – Kyle

相关问题