我想知道通过javascript检查iframe的src是否与给定链接的href相同,这样如果它们等于将类设置为当前
当然,我并不是很了解Javascript,但它会很棒
<script>
changeclass() {
var iframesrc = document.getElementById("videobox").contentWindow.location.href
if(iframesrc=###a.href###) {
var linknumber = ###a.href;
document.getElementById("linknumber").className = "current";
}
}
</script>
<a name="link1" href="samelink" class="current">Video 1</a>
<a name="link2" href="different link" class="">Video 2</a>
<a name="link3" href="different link" class="">Video 3</a>
<iframe name="videobox" src="samelink">
谢谢,我很抱歉没有关于如何在我的代码中使用javascript的最小想法。
答案 0 :(得分:0)
这是你所期待的:
HTML:
<a name="link1" href="samelink" class="current">Video 1</a>
<a name="link2" href="different link" class="">Video 2</a>
<a name="link3" href="different link" class="">Video 3</a>
<iframe id="videobox" name="videobox" src="samelink">
JS:
var iframesrc = document.getElementById("videobox");
var ahref = document.querySelectorAll("a");
var iframePath = iframesrc.getAttribute("src");
for(var i=0;i<ahref.length;i++){
var fhref = ahref[i].getAttribute("href");
if(iframePath == fhref){
var classActive = ahref[i].className = "activeLink";
console.log(classActive);
}
}