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>
quando clicco sul pulsante di ricerca ottengo il seguente errore: "ReferenceError Uncaught: lato sinistro non valido in assegnazione" Ma il codice è in realtà la stessa di quando premo "invio". Qualcuno può spiegare?ReferenceError Uncaught: lato sinistro non valido in assegnazione
Nella funzione 'urlencode()' dovresti usare 'encodeURI()' o 'encodeURIComponent()' invece di 'escape()', che è stato deprecato circa dieci anni fa: http://msdn.microsoft. it/it/us/library/xh9be5xc (VS.85) .aspx http://msdn.microsoft.com/en-us/library/aeh9cef7(VS.85).aspx https://developer.mozilla.org/ it/Core_JavaScript_1.5_Reference/Global_Functions/encodeURI https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent – NickFitz