这是我从这里获得代码的地方: https://www.w3schools.com/php/php_ajax_livesearch.asp
if ($hint=="") {
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
} else {
$hint=$hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
假设我的网站网址是"www.example.com",当我点击显示的结果时,我进入了"https://www.example.com/www.example.com/something.html"的网址
我怎样才能把它弄对?
只需添加HTTP协议即可避免此问题。
if ($hint=="") {
$hint="<a href='https://" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
} else {
$hint=$hint . "<br /><a href='https://" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
您也可以将其设置为动态,而不是硬编码以https://