MouseEnter 上简单的 Jquery 显示问题
我是 stackoverflow 和 Jquery 的新手,所以我想提前为我的经验不足/天真道歉。
所以本质上我试图让一个 div 在按钮处于 mouseEnter 状态时出现。
这是我对 Jquery 的尝试...
$('#main-button-btn-cart').bind('mouseenter', function() {
var $select_button = $('#select-product-reminder');
$select_button.style.display = 'inline-block';
});
而 HTML 是...
<div id="select-product-reminder" style="width:200px; height:30px; background-color:#F00; display:none;">Please Choose an Item</div>
<button type="button" id="main-button-btn-cart" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="productAddToCartForm.submit()">
<?php echo $this->__('+ADD TO CART') ?>
</button>
由于某种原因,此代码不起作用。但是,请注意,如果我在绑定函数中包含警报框,则该警报框确实会出现。
预先感谢您的任何意见!
I am new to stackoverflow and Jquery so I would like to apologize for my inexperience/naivety in advance.
So essentially I am attempting to make a div appear when a button is in the mouseEnter state.
Here's my attempt at Jquery...
$('#main-button-btn-cart').bind('mouseenter', function() {
var $select_button = $('#select-product-reminder');
$select_button.style.display = 'inline-block';
});
and the HTML is...
<div id="select-product-reminder" style="width:200px; height:30px; background-color:#F00; display:none;">Please Choose an Item</div>
<button type="button" id="main-button-btn-cart" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="productAddToCartForm.submit()">
<?php echo $this->__('+ADD TO CART') ?>
</button>
For some reason this code does not work. However, it may be useful to note that if I include an alert box in my bind function, the alert box does appear.
Thanks in advance for any input!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以这样做:
你也可以这样做
onmouseenter 是一个快捷方式,而不是调用绑定函数
you could do this:
also you can do this
onmouseenter is a short cut instead of calling bind function
这应该可以解决问题;
或者你可以去掉 var;
点击更新;
This should do the trick;
Or you could do away with the var;
Update for click;
我会使用类似这样的东西:
$('#main-button-btn-cart').live('mouseenter',function() {
$('#select-product-reminder').show();
});
I would use something that look like this:
$('#main-button-btn-cart').live('mouseenter',function() {
$('#select-product-reminder').show();
});