这可能是这样的:
$(window).load(function() {
// get hash string eg. #video1
var hash = window.location.hash;
if (hash == '#video-1') { // do some checks, you can apply regex or switch
// I'm not sure what your html looks like
$(".main_stage iframe").prop("src", $('selector').attr("href"));
loadURL($(this).attr('href'));
}
});
$(".thumbnail-1,.thumbnail-2,.thumbnail-3").on("click", function(event) {
var className = $(this).attr("class"); // get class name of clicked element
var videoId = className.split("-").pop(); // split string to get video id => "1, 2, 3 etc."
window.location.hash = '#video' + videoId; // change url to eg. #video1
event.preventDefault();
$(".main_stage iframe").prop("src", $(event.currentTarget).attr("href"));
loadURL($(this).attr('href'));
});
如果你这样做验证基于正则表达式(fiddle here),您可以使用此代码:
var hash = window.location.hash;
var regex = new RegExp('^#video-[0-9]{1,10}$');
if (regex.test(hash)) {
// if hash is something like "#video-[NUMBERS]" then do something
}
这就是我一直在寻找的,谢谢!你能仅仅从缩略图部分解释第二个功能,所以我知道我自己是如何工作的,而不是采取你的片段?谢谢:) – user2212564
我会尝试添加一些评论。 –
更新了我的答案,解释了一些代码并添加了正则表达式。 –