0

我有两个问题。第一的。如何减少此代码?

$('#m').click(function() {
    var href = $(this).attr('href');
    $('#con').hide().load('inc/main.php').fadeIn('normal');
    return false;
});
$('#b').click(function() {
    var href = $(this).attr('href');
    $('#con').hide().load('inc/blog.php').fadeIn('normal'); 
    return false;
});
$('#p').click(function() {
    var href = $(this).attr('href');
    $('#con').hide().load('inc/portfolio.php').fadeIn('normal');    
    return false;
});
$('#l').click(function() {
    var href = $(this).attr('href');
    $('#con').hide().load('inc/lebenslauf.php').fadeIn('normal');   
    return false;
});
$('#k').click(function() {
    var href = $(this).attr('href');
    $('#con').hide().load('inc/kontakt.php').fadeIn('normal');  
    return false;
});

我正在使用一个名为完美滚动条的库。它是这样包含的:

$(document).ready(function(a){a("#scrollbox").perfectScrollbar({wheelSpeed:20,wheelPropagation:!1})});

当使用此脚本加载 main.php 时,滚动条不存在。这是因为文档没有像往常一样刷新。我需要写什么才能让它在加载时工作?

4

1 回答 1

0

编写一个函数并将每个选择器和文件路径传递给该函数

$('#m').click(some_function()
{
    helperfunction($(this), 'inc/main.php');
});

function helperfunction(selector, phpfilepath) {
    var href = selector.attr('href');
    $('#con').hide().load(phpfilepath).fadeIn('normal');    
    return false;
}
于 2013-07-23T19:16:29.583 回答