我有一个jquery函数决定向用户显示哪条消息,3条消息中的一条。我在我的页面上有三条消息,每条消息都在各自的隐藏div中。
当用户单击页面上的按钮时,该函数将被调用,根据结果,我希望使用colorbox在弹出窗口中显示3个div (#msg1、#msg2或#msg3)之一。
但是,Colorbox文档使用带有HREF的链接来确定要显示的div;我想使用我的函数。所以我试了一下,但它弹出了颜色盒,但不是我的div,它是空的:
$(function() {
$('#calcbtn').bind('click', function(){
var score = 0;
$('.rb:checked').each(function(){
score+=parseInt($(this).val(),10);
});
// here i have logic to choose the div, assume #msg1 is the div
$(this).colorbox({inline:true, href:"#msg1", width: "50%", height: "50%"});
});
});发布于 2012-12-01 05:13:46
我想我可能有:
$(function() {
$('#calcbtn').bind('click', function(){
var score = 0;
$('.rb:checked').each(function(){
score+=parseInt($(this).val(),10);
});
//$("input[name=sum]").val(score)
//alert('score is '+score);
var $msg;
if (score > 25) {
$msg = $('#msg1');
} else if (score < 15) {
$msg = $('#msg3');
} else {
$msg = $('#msg2');
}
$.colorbox({inline:true, href:$msg, width: "50%", height: "50%"});
});
});https://stackoverflow.com/questions/13652916
复制相似问题