当我尝试搜索C& A之类的内容时,我在Google中遇到的唯一问题是C ... 如何让这个JavaScript转换特殊字符?
function search_google()
{
window.location = "http://www.google.be/search?q=" + document.google.search.value;
}
答案 0 :(得分:7)
您可以使用encodeURIComponent:
function search_google()
{
window.location = "http://www.google.be/search?q=" + encodeURIComponent(document.google.search.value);
}