2012-03-29 14 views
5

हम मोबाइल ब्राउज़र के लिए वेब-ऐप विकसित कर रहे हैं, जब भी इनपुट-बॉक्स फोकस हो जाता है तो हम किसी भी इनपुट बॉक्स का टेक्स्ट चुनना चाहते हैं। नीचे जवाब डेस्कटॉप क्रोम/सफारी ब्राउज़र के लिए समस्या को हल करता है। समाधान नीचे Android ब्राउज़र पर ठीक काम करता है, लेकिन नहीं iPhone/iPad के ब्राउज़र, किसी भी समाधान .. परआईफोन में काम नहीं कर रहे jQuery का उपयोग कर फोकस पर टेक्स्ट का चयन करना आईपैड ब्राउजर

$("#souper_fancy").focus(function() { $(this).select() }); 

$("#souper_fancy").mouseup(function(e){ 
     e.preventDefault(); 
}); 

रेफरी: -

Selecting text on focus using jQuery not working in Safari and Chrome

+3

प्रयास करें http://stackoverflow.com/questions/3272089/programmatically-selecting-text-in-an-input-field-on-ios- डिवाइस-मोबाइल-सफारी – robocat

+1

हां। धन्यवाद रोबकैट, यह यहां पाया गया समाधान - http://stackoverflow.com/questions/3272089/programmatically-selecting-text-in-an-input-field-on-ios-devices- मोबाइल- safari –

उत्तर

4

उत्तर यहां मिला इस प्रश्न को डुप्लिकेट के रूप में चिह्नित करने के बारे में नहीं पता। Programmatically selecting text in an input field on iOS devices (mobile Safari)

इस तरह मेरे ठीक नज़र: -

<script type="text/javascript"> 
      $('div,data-role=page').live('pageshow', function (event) { 
       jQuery.validator.unobtrusive.parse(".ui-page-active form"); 
       $("input[type='text'], textarea, input[type='password'], input[type='number']").live('mouseup', function (e) { e.preventDefault(); }); 
       $("input[type='text'], textarea, input[type='password'], input[type='number']").live('focus', function() {this.setSelectionRange(0, 9999); });    
      });  
    </script> 
1

हो सकता है कि इस प्रयास करें:

vmouseup
टचचेंड या माउसअप घटनाओं को संभालने के लिए सामान्यीकृत घटना

जे एस:

$("#souper_fancy").focus(function() { 
    $(this).select(); 
}); 

$("#souper_fancy").vmouseup(function(e){ 
    e.preventDefault(); 
}); 
+0

यह काम नहीं किया :( –

-1

मेरे लिए यह एक काम करता है।

 $("input[type='text'],select,textarea").focus(function() { 
      $(this).addClass('text-focus'); 
     }); 

     $("input[type='text'],select,textarea").blur(function() { 
      $(this).removeClass('text-focus'); 
     }); 

     .text-focus 
     { 
     border: 1px solid #ea9a00; 
     } 
1

आप document.execCommand('selectAll'); का उपयोग कर सकते हैं। हालांकि यदि उपयोगकर्ता पृष्ठ को स्क्रॉल करता है, तो आपको कॉपी/पेस्ट मेनू दिखाया जाएगा। सच एक स्पर्श डिवाइस के लिए

  • core.iosDevice - - सच एक iOS डिवाइस के लिए

    • mojo.isTouch:

      function trySelect(el, evenInactive, select_ios) { 
          var select = function() { 
           try { 
            if (mojo.isTouch && select_ios && core.iosDevice && mojo.isInput(el) && document.execCommand) { 
             document.execCommand('selectAll'); 
            } else { 
             el.select(); 
            } 
           } catch (e) { 
           } 
          }; 
          if (el && el.select && !el.disabled && (!el.readOnly || el.selectReadOnly) && mojo.isInput(el)) { 
           if (evenInactive || mojo.activeElement() === el) { 
            if (mojo.isTouch && core.webkitVer) { // http://code.google.com/p/chromium/issues/detail?id=32865 
             setTimeout(select, 0); 
            } else { 
             select(); 
            } 
           } 
          } 
      } 
      

      कुछ आंतरिक कार्यों का संदर्भ देता है:

      यह मैं क्या उपयोग है

    • mojo.isInput - इनपुट तत्व के लिए परीक्षण
    • mojo.activeElement() - document.activeElemen टी

    संपादित करें: document.execCommand('selectAll'); का उपयोग नहीं किया जाना चाहिए और el.setSelectionRange(0, el.value.length); इसके बजाए उपयोग किया जाना चाहिए। ऐसा लगता है कि आईओएस 5 पर ठीक काम करता है ... यह आईओएस 4 पर काम नहीं कर सकता है (मेरे पास परीक्षण करने के लिए आईओएस 4 डिवाइस नहीं है)।