我在meteor客户端文件夹中有以下js存档:
var o1, o2, o3, o4, o5, o6, o7, o8, o9, o10;
window.onload = function() {
o1 = document.getElementById("oculta1");
o2 = document.getElementById("oculta2");
o3 = document.getElementById("oculta3");
o4 = document.getElementById("oculta4");
o5 = document.getElementById("oculta5");
o6 = document.getElementById("oculta6");
o7 = document.getElementById("oculta7");
o8 = document.getElementById("oculta8");
o9 = document.getElementById("oculta9");
o10 = document.getElementById("oculta10");
o1.style.visibility = "hidden";
o2.style.visibility = "hidden";
o3.style.visibility = "hidden";
o4.style.visibility = "hidden";
o5.style.visibility = "hidden";
o6.style.visibility = "hidden";
o7.style.visibility = "hidden";
o8.style.visibility = "hidden";
o9.style.visibility = "hidden";
o10.style.visibility = "hidden";
};
function desplegar1() {
o1.style.visibility = "visible";
o5.style.visibility = "visible";
o9.style.visibility = "visible";
alert("hola");
}
function desplegar2() {
o2.style.visibility = "visible";
o6.style.visibility = "visible";
o10.style.visibility = "visible";
}
问题是只执行第一个功能,其余的(desplegar1,desplegar2 ......)都不起作用。有人可以帮帮我吗?
答案 0 :(得分:1)
欢迎来到SO!
HTML中的内联代码是Angular样式。如果你想以这种方式编码,你应该看看angular-compilers
Meteor包。
如果您使用Blaze,则每个JS文件的范围都很大,因此HTML无法通过其名称直接访问JS文件中使用var
声明的函数。甚至可以在构建/缩小期间修改函数名称。
Blaze的常用方法是attach events to your template(Template.<templateName>.events(eventsMap)
)
例如在您的情况下:
Template.myTemplateName.events({
'mouseover td': desplegar1
});
function desplegar1() {
o1.style.visibility = "visible";
o5.style.visibility = "visible";
o9.style.visibility = "visible";
alert("hola");
}