2014-08-31 20 views
0

我在我的應用程序中出現了正確的選擇框,可以選擇(即:可以點擊它們,顯然是做出選擇),但不會按照它們應該的方式行事:PhoneGap在Android上選擇框行爲不端行爲

單擊列表中的某個項目後,該選項的名稱/值未填充到表單中。

我發現很多關於選擇框問題的stackoverflow問題/答案,但他們都不是我的問題。不過,我已經嘗試了這些建議沒有成功,包括把一個高的z-index值的選擇框,加入一些-webkit特定值而CSS等

我已經試過:

<select> box not displaying on Android in PhoneGap

<select> not working in Phonegap app on Android 2.3.3

PhoneGap build webkit-appearance no drop down arrow for select tag

https://github.com/jquery/jquery-mobile/issues/6992

https://www.daniweb.com/web-development/threads/451455/phonegap-select-box-is-not-working

沒有涉及jQuery。

有什麼我失蹤的選擇框?

的example--的HTML:

<select name="people0" id="people0" onfocus="isDirty=1" style="display:inline-block;min-width:150px;" data-native-menu="true"> 
     <option value="0">Choose Person</option> 
      <option value="15098">Desjardins, Emily</option> 
     <option value="17304">Hulley, Patrick</option> 
     <option value="1">Silver, Jason</option> 
</select> 

的CSS:

select{ 
    /* Suggestions found: having trouble with not being able to select items: */ 
    -webkit-user-select: auto !important; 
    -webkit-tap-highlight-color: rgba(0,0,0,0); 
    z-index:1000 !important; 
} 

更新11月8日:

我發現了一個可怕的變通辦法 - 但至少你可以選擇選項。當HTML響應來自服務器,我檢查,看看是否有在它選擇的元素,並把事件偵聽器給他們,如果有:

var allSelectElements = document.getElementsByTagName('select'); 
for (var i=0; i < allSelectElements.length; i++) { 
    allSelectElements[i].addEventListener('touchstart', function(e) { 
     alert('initiating touch'); 
     this.focus; 
    }, false); 
} 

我希望有人能解決這個曾經和換所有。 : -/

+0

有時它似乎如果在選擇框是工作在視圖中,我拖動手指滾動灰色背景,或者在放開之前觸摸並保持該選項一會兒。 – 2014-08-31 17:10:47

+0

發現了一個有趣的方面 - 不是通過增加對click/touchend的關注,而是通過在touchstart上發送一個警告框...只有這樣才能讓它現在能夠工作:\t \t \t \t \t var allSelectElements = document。的getElementsByTagName( '選擇'); \t爲(VAR I = 0;我 2014-11-08 19:54:15

回答

2

我使用類似的代碼解析:

var allSelectElements = document.getElementsByTagName('select'); 
for (var i=0; i < allSelectElements.length; i++) { 
    allSelectElements[i].addEventListener('touchstart', function(e){ 
     //This is the important line 
     e.stopPropagation(); 
    }, false); 
} 
+0

太棒了,出色的工作! – 2015-05-21 17:49:20

0

只是它的工作對我來說是增加了一個jQuery招方式:

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

我用普通的老式javascript編寫,但我會嘗試類似的東西。 – 2014-10-18 01:20:59

+0

請注意我上面的黑客 - 只有這樣才能讓它工作。 (我沒有使用jQuery)...我以編程方式將事件偵聽器添加到選擇框,因此當觸摸它們時,會出現警報。不知何故,這允許選擇一個選項。 – 2014-11-08 19:56:04

+0

如果它適合你,那麼它很酷;) – 2014-11-09 20:50:21