我期待着稍微减少一些代码。像往常一样使用jQuery和Bootstrap,它相当冗长。我想学习如何让它变得更加干爽,并且通过使用我认为是可重用代码艺术的参数和变量的一些组合。寻找智能的方法来使这个Bootstrap/jQuery代码“DRY”
NOTE:这些实际上是相同的唯一真正的区别是“内容”。我将需要使内容和“展示位置”在每个实例中都是唯一的。
实例A
$('#popover-2').popover({
html: true,
trigger: 'manual',
placement:'right',
container:'body',
content:'<h2>EPS Trailing 12 Months</h2><p>Vivamus sagittis lacus vel augue laoreet rutrum faucibus #2</p>'
}).click(function(e) {
$(this).popover('show');
$('.popover-content').prepend('<a class="close">×</a>');
$('.close').click(function(e){
$('[data-toggle=popover]').popover('hide');
});
e.preventDefault();
});
实例B
$('#popover-3').popover({
html: true,
trigger: 'manual',
placement:'right',
container:'body',
content:'<h2>EPS Trailing 12 Months</h2><p>Vivamus sagittis lacus vel augue laoreet rutrum faucibus #2</p>'
}).click(function(e) {
$(this).popover('show');
$('.popover-content').prepend('<a class="close">×</a>');
$('.close').click(function(e){
$('[data-toggle=popover]').popover('hide');
});
e.preventDefault();
});
由于
这个问题似乎是脱离主题,因为它属于codereview.stackexchange.com/ – cfs
@cfs我认为这是一个很有价值的问题,有一个很好的答案。我不知道codereview.stackexchange.com/存在。这是新的吗?这个问题可以移动/迁移到那里以使社区受益吗?谢谢 –