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>
khi tôi nhấp vào nút tìm kiếm tôi nhận được lỗi sau: "ReferenceError chưa gặp: phía bên tay trái không hợp lệ trong chuyển nhượng" Nhưng code đang thực sự giống như khi tôi nhấn "enter". Ai đó có thể giải thích?ReferenceError chưa gặp: không hợp lệ phía bên tay trái trong phân
Trong hàm 'urlencode()', bạn nên sử dụng 'encodeURI()' hoặc 'encodeURIComponent()' thay vì 'escape()', không được dùng khoảng mười năm trước: http://msdn.microsoft. com/vi-us/library/xh9be5xc (VS.85) .aspx http://msdn.microsoft.com/en-us/library/aeh9cef7(VS.85).aspx https://developer.mozilla.org/ vi/Core_JavaScript_1.5_Reference/Global_Functions/encodeURI https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent – NickFitz