我总是用这个。
if (window.location.href != 'search.php') {//get the current url
window.location.href = 'search.php' //redirect
}
试试这些
- alert(document.URL)
- alert(Window.location.href)
- alert(document.location.href)
- alert(window.location.pathname)
用于创建带有链接的下拉列表 - :将其放入 ajax 的成功部分
var data=JSON.parse(xmlhttp.responseText);
var alldata;
for(var i=0;i< data.length;i++)
{
alldata += "<a id='some_id' onclick='myFunction(this.id);' href='whatever#' class='link'>"+data[i][0]+"</a><hr>";
}
//data[i][0]-->this depends on your json text.
document.getElementById('your_input_field_id or div_id').innerHTML = alldata;