Im trying to read a query string from a url and alert a message based on the query string. The strings are being passed on perfectly, I am just haveing trouble reading them on the page. what am i doing wrong?
possible query strings
.../playlist.html?vid=1
.../playlist.html?vid=2
js
$(function () {
if (window.locaion.search.indexOf('vid=1') > -1) {
alert('1');
} else if (window.locaion.search.indexOf('vid=2') > -1) {
alert('2');
}
});
更改window.locaion
到window.location
Two problems: you mistyped location, and you need to toString() it, because location isn't a string. So the corrected version:
$(function () {
if (window.location.toString().indexOf('vid=1') > -1) {
alert('1');
} else if (window.location.toString().indexOf('vid=2') > -1) {
alert('2');
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.