我有这个事件处理程序,我可以记录 DOM 元素,但我不能用它做任何事情。设置显示或任何内容都没有任何效果。
Template.layoutTemplate.events({
'mouseover .top_nav_button': function(ev){
ev.preventDefault();
console.log($(this).css('padding'));
$(this).css('display', 'none');
}
});
模板代码如下:
<template name = 'layoutTemplate'>
<div id = 'top_nav'>
{{> loginButtons}}
<a class='top_nav_button' id = 'about_snipex_button' href="{{pathFor 'about'}}">About Snipex</a>
<a class='top_nav_button' id = 'become_verified_button' href="{{pathFor 'verified'}}">Become Verified!</a>
<a class='top_nav_button' id = 'terms_button' href="{{pathFor 'terms'}}">Terms&Conditions</a>
</div>
<h1 id='layout_header'><a id = 'home_button' href="{{pathFor 'home'}}">snippetExchange</a></h1>
<div id='layout_header_row_2'>
<h2 id='layout_by_line'><a id = 'home_button' href="{{pathFor 'home'}}">valuable answers</a></h2>
</div>
<div id='sub_nav'>
<a class='sub_nav_button' id = 'notifications_button' href="{{pathFor 'notifications'}}">notifications</a>
<a class='sub_nav_button' id = 'my_history_button' href="{{pathFor 'user_profile' _id=currentUser}}">my history</a>
<a class='sub_nav_button' id = 'new_post_button' href="{{pathFor 'new_post'}}">new post</a>
</div>
{{> yield}}
</template>
最佳答案
display
规则没有值作为hidden
。
将其更改为 $('#top_nav').css('display', 'none');
Hidden是css中visibility
规则的属性。
关于javascript - DOM 元素存在,jQuery 无法操作它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30384564/