我试图只在span#attr-val为空时显示#tooltip。但我的IF语句似乎没有起作用,工具提示总是显示跨度是否为空......任何帮助都非常感谢!
$(document).ready(function() {
if ($("#attr-val").is(":empty")) {
$("#addtobag > input").hide( );
$("#addtobag").hover(function(e){
this.t = this.title;
this.title = "";
$("#addtobag").css("cursor","pointer");
$("body").append("<p id='tooltip'>Please Select A Size</p>");
$("#tooltip")
.css("top",(e.pageY - 10) + "px")
.css("left",(e.pageX + 20) + "px")
.show();
},
function(){
$("#tooltip").remove();
});
$("#addtobag").mousemove(function(e){
$("#tooltip")
.css("top",(e.pageY - 10) + "px")
.css("left",(e.pageX + 20) + "px");
});
}
});
示例HTML如下:
<div>
<div class="options">
<span class="prompt">
Size: <span id="attr-val"></span><br />
</span>
<span>
<input type="radio" name="Product_Attributes[1]:value" value="6" /> <a class="radio-select" href="#">6</a></span>
<span>
<input type="radio" name="Product_Attributes[1]:value" value="6.5" /> <a class="radio-select" href="#">6.5</a></span>
<p class="soldout" title="Sold Out">7</p>
<br class="clear" />
</div>
<span id="addtobag"><input type="image" src="/images/2011/btn_addtobag.gif" alt="" /></span>