iScroll 4 无法与表单
我正在使用以下 HTML 代码:
<form action="#" method="post">
<fieldset>
<label class="desc" id="title10" for="Field10">
How many children do you have?
</label>
<select id="Field10" name="Field10" class="field select large" tabindex="5">
<option value="0" selected="selected">0 </option>
<option value="1">1 </option>
<option value="2">2 </option>
<option value="3">3 </option>
<option value="4">4 </option>
<option value="5">5 </option>
<option value="6">6 </option>
<option value="7">7 </option>
<option value="8">8 </option>
<option value="9">9 </option>
</select>
<input type="submit" value="Send message" />
</fieldset>
</form>
我正在使用 iScroll 4,它造成了问题。
<script type="application/javascript" src="iscroll-lite.js"></script>
<script type="text/javascript">
var myScroll;
function loaded() {
myScroll = new iScroll('wrapper');
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
</script>
我认为这是一个解决方案,但我不知道如何实施。
I'm using this HTML code:
<form action="#" method="post">
<fieldset>
<label class="desc" id="title10" for="Field10">
How many children do you have?
</label>
<select id="Field10" name="Field10" class="field select large" tabindex="5">
<option value="0" selected="selected">0 </option>
<option value="1">1 </option>
<option value="2">2 </option>
<option value="3">3 </option>
<option value="4">4 </option>
<option value="5">5 </option>
<option value="6">6 </option>
<option value="7">7 </option>
<option value="8">8 </option>
<option value="9">9 </option>
</select>
<input type="submit" value="Send message" />
</fieldset>
</form>
<select>
is not working on iPhone and Android. When I tap on the selectbox nothing happens.
I'm using iScroll 4 which is creating the problem.
<script type="application/javascript" src="iscroll-lite.js"></script>
<script type="text/javascript">
var myScroll;
function loaded() {
myScroll = new iScroll('wrapper');
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
</script>
I think this is a solution but I don't know how to implement it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
问题是 iScroll 取消了
select
标记的默认行为(如果你问我的话,这不是一个很好的实现)。这发生在第 195 行的
_start()
函数中:如果您将其注释掉,您会发现
select
标记再次起作用。但将其注释掉意味着您已经破解了该库,这可能会破坏其他所需的 iScroll 功能。因此,这里有一个更好的解决方法:
该代码将允许发生默认行为,而不会将事件传播到 iScroll,在那里它会搞砸一切。
由于您的 JS 不在任何类似 jQuery 的
onReady()
事件中,因此您必须确保将此代码放在您select 的 HTML 之后
元素已定义。请注意,对于移动设备,事件为
touchstart
,但对于 PC 浏览器,事件为mousedown
The problem is that iScroll cancels the default behavior of your
select
tag (Not a very good implementation if you ask me).This occurs in the
_start()
function on line 195:If you comment that out you'll notice the
select
tag works again.But commenting it out means you've hacked the library which might break other desirable iScroll functionality. So here's a better workaround:
That code will allow the default behavior to occur, without propagating the event to iScroll where it screws everything up.
Since your JS is not inside any jQuery-like
onReady()
event, you'll have to make sure to you put this code AFTER the HTML where yourselect
elements are defined.Note that for mobile devices the event is
touchstart
, but for your PC browser it will bemousedown
我在 android 上的 iScroll 4.1.9 上遇到了同样的问题,我只是替换了第 95 行(在我的版本上):
by :
启用对输入、选择和文本区域标签的关注
I had the same issue on the iScroll 4.1.9 on android, I just replaced the line 95 (on my version) :
by :
that enable focus on input, select and textarea tags
终于在 Android 上修复了这个问题。最终修改了 iscroll.js 中的几行
以下是我们初始化 iScroll 的方法。
onBeforeScrollStart 允许控件执行默认行为。 Android浏览器好像useTransform有问题,所以转为false。
最后,当 useTransform 为 false 时,需要排除一些额外的 iscroll 代码:
尝试了其他几种方法,然后意识到它与 iscroll 添加的 css 有关。
Finally fixed this for Android. Ended up modifying a couple of lines in iscroll.js
Here's how we initialize iScroll.
The onBeforeScrollStart is what allows the controls' default behaviors to take place. Android browser seems to have problem with useTransform, so turn to false.
Finally, some additional iscroll code needed to be excluded when useTransform is false:
Tried several other methods before realizing that it had to do with the css that iscroll adds.
我知道迟到了,但这可能对某些人有帮助,
在 pageshow 事件中编写以下代码,但请确保 div id 不相同。
这是因为,iscroller 阻止了元素的默认行为
I Know am late,but it might be helpful for some one,
write the following code in pageshow event,but be sure that div ids not same.
it is because, iscroller prevents the default behaviors of elements
这是解决方案
Here is the solution
解决方案的另一个代码示例。并感谢之前的评论!
使用 Jquery!
之后:
在加载的函数中
another code example for solution. and thanks for previous comments!
Using Jquery!
After:
in loaded function
替换行,
onBeforeScrollStart: function (e) { e.preventDefault(); },
通过
在
iScroll.js
中工作Replacing line,
onBeforeScrollStart: function (e) { e.preventDefault(); },
By
In
iScroll.js
Works从这段代码开始。这个解决方案对我有用:
Start with this code. This solution worked for me:
我迟到了,但我给你留下了我的解决方案。
如果你正在使用 jQuery,你可以尝试一下。
I'm late but I leave you my solution.
If your are using jQuery you can try that.
对我来说,我只需要在最后一行添加 click: true ......
花了一整天的时间调试并实施所有建议的解决方案,但无济于事......
For me, I just need to add click: true on the last line...
Spent the whole day debugging and implementing all the suggested solutions to no avail...
他任何人。
我知道你所有的答案,但我有新的方法可以提供。没有java脚本或drop iscroll函数。
所有这些解决方案的大问题是,当您在输入元素上滚动时,页面上没有滚动。当您只进行一两个输入时并不重要,但是当页面是一种表单时,您在滚动页面时会遇到很大的问题。
我提供的解决方案是将输入包装在标签标签中,或者使用指向输入的指针来制作标签标签。然后使用绝对定位和 z 索引将标签置于输入上方。当您触摸标签时,您将集中输入。
示例请为
HTML
CSS,
您也可以通过这种方式将标签侧放在输入中,并将输入的绝对位置放入标签区域中,
以 100% 工作,检查一下
he anyone.
i know's about all your answer's but i have new way to offer. without java-script or drop iscroll functions.
the big problems with all this solution is when you scroll on input's element you have no scroll on the page. when you make just one or two input's isn't really matter but when the page is a form you have big problem to scroll the page.
the solution i offering is to wrap the input in label tag or make the label tag with for pointer to the input. then make with absolute positioning and z-index the label above the input. when you touch on the label you focus the input.
and example please
HTML
CSS
you can also in this way put the label side of the input and with position absolute of the input put that into the label area
is working in 100%, check it
当 -webkit-transform:translate3d 应用于具有选择框或密码框的容器时,Android 存在一个错误[1]。激活这些元素的方框区域会移动,并且不在您认为的位置。此外,密码框绘制在不同的位置,因此看起来您有两个输入元素,而不是一个。
我在 AppMobi 工作,我们开发了一个工具包库来修复这些问题。我们已经实现了自定义选择框小部件和密码输入字段的替代品。看看下面。
https://github.com/imaffett/AppMobi.toolkit
[1] 我认为作者评论正在谈论这个错误 https://bugs.webkit.org/show_bug.cgi?id=50552
There is a bug with Android when -webkit-transform:translate3d is applied to a container that has a select box or password box[1]. The boxed area to activate those elements move, and are not where you think they'd be. Additionally, password boxes paint in a different location, so it appears that you have two input elements instead of one.
I work at AppMobi and we have developed a toolkit library that has fixes for these. We've implemented custom select box widgets and a replacement for the password input field. Check it out below.
https://github.com/imaffett/AppMobi.toolkit
[1] I think the author of the comment is talking about this bug https://bugs.webkit.org/show_bug.cgi?id=50552
我有点晚了,但如果有人仍然感兴趣,我采用了@bastien的方法并对其进行了调整让它在 Android 上运行。我在实施中使用 JQM。
基本上我所做的是:
基本上,您需要做的就是在用户选择表单元素时销毁 iScroll 实例,但在它们实际开始滚动(onBeforeScrollStart)之前,并且如果用户使用自定义单击元素内的其他任何内容属性
data-iscroll="scroller"
,他们可以像往常一样使用 iScroll 滚动。I'm a bit late to the game, but if anyone is still interested, I took @bastien's approach and tweaked it a bit to get it to work on Android. I'm using JQM with my implementation.
Basically what I did was:
Basically all you need to do is destroy your iScroll instance when a form element is selected by the user, but before they actually start scrolling (onBeforeScrollStart) and if the user clicks on anything else within the element with the custom attribute
data-iscroll="scroller"
, they can scroll using iScroll as usual.这是一个非常简单的修复方法,对我有用。我注意到在 Android 浏览器中,在初始页面加载时,我无法单击选择框,但可以单击用于搜索的文本输入字段。然后我注意到,在单击文本输入字段后,它会识别我单击选择框。所以我所做的就是将其添加到我用来加载搜索页面的 javascript 函数中...
因此,当加载搜索页面时,它会自动聚焦于文本输入字段,但不会弹出键盘,这正是我想要。抱歉,我的示例无法公开访问,但希望这仍然可以对某人有所帮助。
Here's a really easy fix that worked for me. I noticed in the Android browsers that on initial page load I could not click on a select box but I was able to click on a text input field that I was using for Search. Then I noticed that after I clicked on the text input field, it would recognize me clicking a select box. So all I did was add this to the javascript function I was using to load the Search page...
So when the search page gets loaded, it automatically focuses on the text input field but does not pop up the keyboard, which is exactly what I wanted. Sorry my example is not publicly accessible, but hopefully this can still help somebody.
尝试这个解决方案
if (e.target.nodeName.toLowerCase() == "选择" || e.target.tagName.toLowerCase() == '输入' || e.target.tagName.toLowerCase() == '文本区域')
{
返回;
}
try this solution
if (e.target.nodeName.toLowerCase() == "select" || e.target.tagName.toLowerCase() == 'input' || e.target.tagName.toLowerCase() == 'textarea')
{
return;
}
怎么样,这对我有用!:
What about, that works for me!:
即使您在 onBeforeScrollStart() 中排除了表单元素,android 2.2/2.3 browser/webview 中还有另一个错误:
https://www.html5dev-software.intel.com/viewtopic.php?f=26&t=1278
https://github.com/01org/appframework/issues/104
你不能使用“-webkit-transform”css样式在div的输入元素中输入中文字符。 iscroll 4 对滚动条 div 应用了“-webkit-transform”。
解决方案是将表单字段保留在滚动条之外的绝对 div 中。
Even if you've excluded form elements in onBeforeScrollStart(), there is another bug in android 2.2/2.3 browser/webview:
https://www.html5dev-software.intel.com/viewtopic.php?f=26&t=1278
https://github.com/01org/appframework/issues/104
You can't input chinese characters in input elements in the div with "-webkit-transform" css style. The iscroll 4 applied the "-webkit-transform" with the scroller div.
The solution is to keep form fields in a absolute div out of the scroller.
Android 浏览器错误是 Android 内部非常旧的 WebKit 版本(甚至 Android 4.3 内部)造成的。 bug的根本原因——iScroll发回浏览器的点击事件处理错误(去掉preventDefault只是停止发送这个点击事件)
Android Chrome浏览器没有这个bug,因为它内部升级了WebKit库。
等待 Google 的 Android WebKit 升级。
Android browser bug is result of very old version of WebKit inside Android, even inside Android 4.3. The root cause of bug - wrong processing of the click event that iScroll sends back to the browser (removing preventDefault just stops sending this click event)
The Android Chrome browser is free from this bug because it has upgraded WebKit library inside.
Waiting for Android WebKit upgrade from Google.
检查一下。这解决了我的问题
https://github.com/cubiq/iscroll/issues/576
在我选择的选项中
Check this. This fixed my issue
https://github.com/cubiq/iscroll/issues/576
In option I have selected