尝试编写javascript,从下面的网址打印“username = john01”和“password = password123”。目前它什么都没打印......
<html>
<body>
<p> This code is for educational purposes only, and is not to be used with malicious intent. </p>
<script>
string = window.location.search;
content = string.split("");
usernameStart = 1;
usernameEnd = content.indexOf("&",0);
username = content.substring(usernameStart,usernameEnd));
document.write("Your username is " + username);
</script>
</body>
</html>
答案 0 :(得分:0)
var url = 'index.html?username=john01&password=password123<=_c1F9F2B16-96B3-9D7B-CC19-D22A43D4FCA1_kA54D6D0E';
var username = url.match(/username=([^&]*)/)[1];
var password = url.match(/password=([^&]*)/)[1];
document.getElementById('userinfo').innerHTML = 'Your username is ' + username + '<br/>And your password is ' + password;
您可以直接在JSFiddle
上试用如果将'url'替换为'window.location'并删除第一行,则应该从该URL开始。