<选择>无法在 Android 2.3.3 上的 Phonegap 应用程序中工作

发布于 2025-01-05 04:48:51 字数 810 浏览 1 评论 0原文

我正在开发适用于 Android 和 iOS 的 Phonegap 应用程序。大多数东西都工作得很好,但我遇到了

  1. 在包含
  2. 在 div 上方的区域上

在这种情况下,选项会显示,并且当选定的更改事件被触发并且代码绑定到它时被执行。

我发现这两个安卓问题: http://code.google.com/p/android/issues/detail?id=10280< /a> 和 http://code.google.com/p/android/issues/detail?id=6721< /a>

我已经尝试了那里提到的解决方法,但它们没有改变任何东西。我仍然需要点击两次,但这不是我想要的行为。我只需要点击一下。

问题仅存在于 Android 2.3.3 上,我认为旧版本上也存在。在 iOS 和更新的 Android 上,一切都运行得很好。

我一整天都在为这个问题苦苦挣扎,并尝试了一切。

任何帮助、提示将不胜感激。 谢谢。

I'm working on Phonegap app for Android and iOS. Most of the stuff works pretty well but I'm experiencing a problem with <select> tag. It's enhanced with jQuery mobile and on that version of Android when the appropriate div is clicked / tapped the options are not showing up. They show up when I do two clicks / taps:

  1. on a div containing <select>
  2. on a area above the div

In that scenario options show up and when selected change event is fired and code bind to it is executed.

I found these two android issues:
http://code.google.com/p/android/issues/detail?id=10280 and
http://code.google.com/p/android/issues/detail?id=6721

I have tried the workarounds mentioned there but they don't change anything. I still have to do two clicks but it's not the behavior I'm after. I only need one click.

Issue exists only on Android 2.3.3 and I think on older versions too. On iOS and newer Androids everything works perfectly fine.

I'm struggling with this issue whole day and tried everything.

Any help, tips would be heavily appreciated.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

淑女气质 2025-01-12 04:48:52

您是否尝试将 data-native-menu="false" 属性添加到选择菜单中?

例子:

<select name="gender" id="gender" data-theme="b" data-native-menu="false" >
    <option value="">Please specify ...</option>
    <option value="option1">Male</option>
    <option value="option2">Female</option>
    <option value="option3">Undisclosed</option>
</select>

Did You try adding data-native-menu="false" attribute to the select menu.

Example:

<select name="gender" id="gender" data-theme="b" data-native-menu="false" >
    <option value="">Please specify ...</option>
    <option value="option1">Male</option>
    <option value="option2">Female</option>
    <option value="option3">Undisclosed</option>
</select>
柠檬色的秋千 2025-01-12 04:48:52

这就是解决我的问题的方法。在 android 2.3.x 中,我将选择框上的 z-index 设置为 ~1000(远高于其他元素),它解决了问题。显然,本机浏览器弄乱了“层”。希望有帮助。

This is what solved my problem. In android 2.3.x I've set z-index on select box to ~1000(far above other elements) and it solved the problem. Apparently native browser is messing up the "layers". Hope it helps.

玩心态 2025-01-12 04:48:52

对于 android 2.3 和 JavaScript 生成的选择框也有同样的问题,我的解决方案是使用 jQuery 在元素渲染后以及每次再次渲染时将其聚焦(即使使用 $.SELECT.show())。

执行 $("#element").focus() 后,选择框再次正常运行,它既可单击,又在选择新选项后更新。

Having the same problem with android 2.3 and a JavaScript generated select box, my solution for this was using jQuery to focus the element once it was rendered and every time it was rendered again (even if using $.SELECT.show()).

After doing $("#element").focus() the select box behaves normally again, its both clickable and updates after selecting a new option.

往事随风而去 2025-01-12 04:48:52

我遇到了同样的问题,我意识到问题是因为我使用了 data-position="fixed" 属性作为包含 select 元素的页面标题。当我从标题中删除 data-position="fixed" 时,标题确实没有固定,但摆脱了选择不被“单击”的恼人问题。希望这有帮助!

I had the same problem, i realized the problem was because i had used data-position="fixed" property for the heading of the page which contained the select element. when i removed data-position="fixed" from my heading, heading was not fixed surely, but got rid of this annoying problem of selects not being 'clicked'. hope this helps!

末蓝 2025-01-12 04:48:52

它对我有用的唯一方法是将其添加到我的 jQuery 脚本中:

$('select').click(function () {
    $(this).focus();
});

The only way it worked for me was adding this on my jQuery script:

$('select').click(function () {
    $(this).focus();
});
寄风 2025-01-12 04:48:52

我已经尝试了你所有的建议但没有运气。
我最终得到的不是最好的解决方案,但它比替代方案更好,如果没有其他方法可以更新选择框。
我用 jQuery 做了这样的事情:

$(".select_box").change(function() {
    $(this).hide();
    $(".select_box").show();
});

Bum,更新了。

请记住,如果没有其他办法,这只是一个解决方案。

I have tried all of your suggests with no luck.
What i've ended up with is not the best solution, but it's better than the alternative, if nothing else will update the select box.
I did it with jQuery like this:

$(".select_box").change(function() {
    $(this).hide();
    $(".select_box").show();
});

Bum, updated.

Please remember, that this is only a solution if nothing else will work.

诠释孤独 2025-01-12 04:48:52

确保您的 div 页面不在另一个 div 内。它应该看起来像:

<body>
  <div data-role="page">
    ...
  </div>
 </body>

不是这样的:

<body>
  <div>
    ...
    <div data-role="page">
      ...
    </div>
    ...
  </div>
</body>

我使用带有 data-native-menu="true"select 遇到了完全相同的问题,并且在我删除它后一切正常额外的div

Make sure your div page is not inside another div. It should look like:

<body>
  <div data-role="page">
    ...
  </div>
 </body>

NOT like this:

<body>
  <div>
    ...
    <div data-role="page">
      ...
    </div>
    ...
  </div>
</body>

I had exactly the same problem using a select with data-native-menu="true" and all worked fine once I removed that extra div.

遮了一弯 2025-01-12 04:48:52

我知道这个问题是两年前发布的,但以防万一今天有人遇到这个问题,就像我最近所做的那样:

我的行为与您所说的相同。
我遇到的问题是一个 div 作为标题出现,并且具有属性 data-role="header" 和 data-position="fixed"。 jquery mobile 中存在一个错误,会导致 Android 2.2/2.3 中出现许多奇怪的问题 (http://demos.jquerymobile.com/1.3.2/widgets/fixed-toolbars/)。

我修复了该错误,从标题中删除“data-position =“fixed””并使用以下代码添加自定义类:

.custom-header{
    position: fixed !important;
    left: 0px !important;
    right: 0px !important;
    top: 0px !important;
    z-index: 999 !important;
}

希望它对某人有帮助。

I'm aware this question was published two years ago, but just in case someone face this problem today, as I did recently:

I had the same behaviour as the one you tell.
The problem I had was with a div that appeared as a header and had the attribute data-role="header" and data-position="fixed". There's a bug in jquery mobile that causes a number of strange issues in Android 2.2/2.3 (http://demos.jquerymobile.com/1.3.2/widgets/fixed-toolbars/).

I fixed that error removing 'data-position="fixed"' from the header and adding a custom class with the following code:

.custom-header{
    position: fixed !important;
    left: 0px !important;
    right: 0px !important;
    top: 0px !important;
    z-index: 999 !important;
}

Hope it helps somebody.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文