简体   繁体   English

jQuery Show / Hide在Android上不起作用

[英]jQuery Show / Hide doesn't work on Android

I am working with a mobile app in Phongap and Cordova. 我正在Phongap和Cordova中使用移动应用程序。 Using OnsenUI. 使用OnsenUI。

In one page I have an ons-switch elements that shows and hide a select html element. 在一页中,我有一个ons-switch元素,该元素显示和隐藏select html元素。

The peculiar thing of this is that the js code that shows and hides the select when touching the ons-switch works fine on iOS (tested on iPhone 5S) and on the Android Emulator, but when I deploy the app on my Samsung Galaxy S4 (Android 4.3) the script doesn't work, it doesn't hide/show the select. 奇怪的是,触摸ons-switch时显示和隐藏选择的js代码在iOS(在iPhone 5S上测试)和Android模拟器上都能正常工作,但是当我在Samsung Galaxy S4上部署应用程序时( Android 4.3)脚本不起作用,也不会隐藏/显示所选内容。

The Android version that the code is not working is 4.3. 代码无法正常运行的Android版本是4.3。 The phonegap version is 4.2.0-0.25.0. phonegap版本是4.2.0-0.25.0。 The Cordova version is 4.3.0. Cordova版本为4.3.0。

Here is my code: 这是我的代码:

    <ons-page>

        <ons-toolbar>
            <div class="left"><ons-back-button>Back</ons-back-button></div>
            <div class="center">MyPage</div>
        </ons-toolbar>

        <div style="text-align:center">
            <div style="margin-top:5%;width:100%;">
                <input class="text-input" id="my-input">
            </div>

            <div style="width:100%;float:left;clear:both">
                <label>Show Select 1</label>
                <ons-switch var="switch1" onchange="ShowSelect1()"></ons-switch>
                <select id="select1"></select>
            </div>

            <div>
                    <label>Show Select 2</label>
                    <ons-switch var="switch2" onchange="showSelect2()"></ons-switch>
                  <select id="select2"></select>
            </div>
</div>
    </ons-page>

My Js Code: 我的Js代码:

 function ShowSelect1() {
            var item = $("#select1");
            if (switch1.isChecked()) {
                 item.show();
            } else {
                item.hide();
            }
        }

        function ShowSelect2() {
            var item = $("#select2");
            if (switch2.isChecked()) {
                item.show();
            } else {
                item.hide();
            }
        }

Don't use jQuery hide and show for something like this, use the Angular that onsen is based on. 不要使用jQuery隐藏和显示这样的东西,而应使用onsen基于的Angular。 Use an ng-show or ng-hide and base it off of a scope value. 使用ng-show或ng-hide并将其基于范围值。 You aren't showing enough of your code to properly show you a fix, but something like: 您显示的代码不足以正确显示修复程序,但类似:

<ons-switch var="switch2" ng=change="select2Hiding = !select2Hiding"></ons-switch>
<select id="select2" ng-hide="select2Hiding"></select>

in your html and remove the JS Code... 在您的html中,然后删除JS代码...

The jQuery used by Angular is overriden by a version of jQuery for Angular's purpose. Angular所使用的jQuery被jQuery版本覆盖。 Both $.hide() and $.show() are overriden by ng-show and ng-hide . $.show() $.hide()$.show()都被ng-showng-hide覆盖。

Use those and everything will work fine. 使用这些,一切都会正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM