我想知道是否可以使用“Javascript URL”,
像这样:
http://example.com/index.php#login-failed
这会使输入变为红色并显示“登录失败,再试一次”或类似的东西?
答案 0 :(得分:0)
您可以使用以下内容:
if ( window.location.hash === '#login-failed' ) {
alert( 'Your login just failed a lot.' );
}
检查当前哈希值,这可能是您所描述的" Javascript Url"。
另外,您可能需要查看window.onhashchange()事件。
答案 1 :(得分:0)
Window.location所有示例
window.location = {
hash: '#myAnchor',
host: 'davidwalsh.name',
hostname: 'davidwalsh.name',
href: 'http://davidwalsh.name:80/article.php?s=david+walsh+blog#myAnchor',
pathname: '/article.php',
port: '80',
protocol: 'http:',
search: '?s=david+walsh+blog',
replace: 'function replace() { [native code] }',
assign: 'function assign() { [native code] }',
reload: 'function reload() { [native code] }'
}
在你的情况下:
window.location.href="http://example.com/index.php#login-failed";
答案 2 :(得分:0)
此??
if(window.location.hash == "#login-failed")
{
var message = document.getElementById("your_message_element");
message.innerHTML = "Login failed, try again";
message.style.color = "red";
}