2009-12-22 14 views
24
<script> 
function urlencode(str) { 
    return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40'); 
} 
$('input#q').keyup(function(e) { 
if(e.keyCode == 13) { 
    if($('input#q').val().length > 2) 
    { 
    $('input#q').val() = urlencode($('input#q').val()); 
    document.search_form.submit(); 
    } 
} 
}); 
$('input#search').click(function() { 
if($('input#q').val().length > 2) 
{ 
    $('input#q').val() = urlencode($('input#q').val()); 
    document.search_form.submit(); 
} 
}); 
</script> 

जब मैं खोज बटन मैं निम्नलिखित त्रुटि मिलती है पर क्लिक करें: "Uncaught ReferenceError: काम में अवैध बाएं हाथ की ओर" लेकिन कोड वास्तव में के रूप में जब एक ही है मैं "एंटर" दबाता हूं। क्या कोई समझा सकता है? - हो सकता है पेज हैUncaught ReferenceError: काम में अवैध बाएं हाथ की ओर

$('input#q').val(urlencode($('input#q').val())) 

यह कुंजी दबाने या तो के साथ काम नहीं करेंगे:

+0

'urlencode()' फ़ंक्शन में आपको 'एन्कोडुरि()' या 'एन्कोडुरिकॉम्पोनेंट() 'का उपयोग' एस्केप()' के बजाय किया जाना चाहिए, जिसे लगभग दस साल पहले हटा दिया गया था: http://msdn.microsoft। कॉम/एन-यूएस/लाइब्रेरी/xh9be5xc (वीएस.85) .aspx http://msdn.microsoft.com/en-us/library/aeh9cef7(VS.85).aspx https://developer.mozilla.org/ एन/कोर_जवास्क्रिप्ट_1.5_ संदर्भ/वैश्विक_फंक्शन/एनकोडुरि https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent – NickFitz

उत्तर

33

आप एक समारोह

$('input#q').val() = urlencode($('input#q').val()); 

इस बजाय प्रयोग का परिणाम के लिए एक नया मूल्य असाइन नहीं कर सकते बस एक ही जेएस त्रुटि के बाद जमा किया।

संबंधित मुद्दे