如何在查询中使用特殊字符

Ian*_*ers 1 html javascript special-characters

当我尝试搜索C&A之类的东西时,我在Google中获得的唯一查询是C ...如何让这个JavaScript转换为特殊字符?

    function search_google()
{
    window.location = "http://www.google.be/search?q=" + document.google.search.value;
}
Run Code Online (Sandbox Code Playgroud)

Răz*_*nda 7

你可以使用encodeURIComponent:

function search_google()
{
    window.location = "http://www.google.be/search?q=" + encodeURIComponent(document.google.search.value);
}
Run Code Online (Sandbox Code Playgroud)