我确定这只是我的语法问题,但我正在尝试将变量发送到 iframe(供 colorbox 使用)。目前我接受两端的任何域(只是为了让它工作)。这是发送页面的js:
$(document).ready(function() {
if(window.location.hash) {
var urlimage = window.location.hash.substring(1);
targetiframe = document.getElementById('wbgallery').contentWindow;
targetiframe.postMessage(urlimage, "*");
console.log(urlimage);
}
});
Run Code Online (Sandbox Code Playgroud)
这是接收页面:
$(document).ready(function() {
window.addEventListener('message',receiveMessage);
console.log(event);
function receiveMessage(event) {
if (origin !== "*")
return;
inbound = event.data;
console.log(inbound);
}
});
Run Code Online (Sandbox Code Playgroud)
我看到了 urlimage 的控制台日志,可以看到一个事件,但没有任何入站事件。我正在使用Mozilla 的解释来尝试解决所有问题。
为什么下面的文字是红色的?
#stories li a {color:red}
.default li.expand a {color:green}
li.expand a {color:blue}
Run Code Online (Sandbox Code Playgroud)
<ul id="stories" class="default">
<li>this is the end</li>
<li class="expand">this is the end</li>
Run Code Online (Sandbox Code Playgroud)
只有当我把#stories放在其他文件上时,文本才会改变.#是否有更多的优势,即使它进一步上升到css?!
我正在Karl Swedberg的博客上阅读关于绑定和解除绑定事件的伟大文章(因为我是js初学者使用jQuery),我对这部分代码感到非常困惑(简化为简洁):
function addItemUnbind() {
$Add a button but it won't have it's event added;
addItemUnbind();
});
Run Code Online (Sandbox Code Playgroud)
为什么通过在自身内部放置相同的函数,它不会继续执行无限循环?但是,它用于将事件重新绑定到元素...!