您好我试图在模式中显示不同的内容,具体取决于点击的内容。模态工作正常,但我试图找到一种更有效的方法来编写以下代码来显示内容。
$(document).ready(function(){
$('#block').hasClass('block1'); {
$('.block1').click(function(){
modal.open({content: $("<p>display this content</p>"), width: "500px", height: "200px"});
})
}
$('#block').hasClass('block2'); {
$('.block2').click(function(){
modal.open({content: $("<p>has different content</p>"), width: "500px", height: "200px"});
})
}
$('#block').hasClass('block3'); {
$('.block3').click(function(){
modal.open({content: $("<p>and again different</p>"), width: "500px", height: "200px"});
})
}
});
答案 0 :(得分:0)
$(document).ready(function(){
$('.block').click(function(){
var content = '';
if($(this).hasClass('block1'))content = 'content1'
if($(this).hasClass('block2'))content = 'content2'
if($(this).hasClass('block2'))content = 'content3'
modal.open({content: $("<p>" + content + "</p>"), width: "500px", height: "200px"});
})
});