我正在尝试在JavaScript中提取当前文件名,而不使用任何参数。
$(location).attr('href').match(/([a-zA-Z\-\_0-9]+\.\w+)$/);
var current_path = RegExp.$1;
if ((current_path == 'index.html') || ...) {
// something here
}
但是,当您像http://example.com/index.html?lang=ja这样访问时,它根本不起作用。 当然,在文件名之前会随机更改。 有什么想法?
$(location).attr('href')
===location.href
JavaScript是jQuery的前置条件,而不是反过来。 - qwertymk