Jquery我需要应用具有不同特征的相同函数

时间:2015-08-04 15:28:31

标签: javascript jquery

我需要的是应用一个jquery函数三个元素,但具有不同的功能,如淡入/淡出,FB.XFBML.parse等。我试图抛开功能不起作用,我知道我在做什么错了,我能伸出援助之手吗?

这是jQuery代码:

function load(div, of) {
    $(div).load(of, function() {    
        FB.XFBML.parse(document.getElementById('div-d'));
        twttr.widgets.load();
    }).hide().fadeIn("slow");    
}

$.getScript("jquery.cycle.all.js", function(data, textStatus, jqxhr) {
    console.log(data); // Data returned
    console.log(textStatus); // Success
    console.log(jqxhr.status); // 200
    console.log("Load was performed.");
});

options = $.extend( options || {}, {
    dataType: "script",
    cache: true,
    url: url
});

$(document).ready(function(){
    $("#Reload").click(function() {
        $("#result").html("result reloaded successfully");
    });
});

按钮1:

<a href="#inicio" onClick="load('.div-d','road.php')" class="temas-deco-d">ROAD</a>

按钮2:

<a href="#inicio" onClick="load('.div-d','street.php')" class="temas-deco-d">STREET</a>

BUTTON3:

<a href="#inicio" onClick="load('.div-d','house.php')" class="temas-deco-d">house</a>

按钮1想要加载没有FB.XFBML.parse的div。

两个按钮想要加载没有fade effect

的div

我希望按钮三加载脚本jquery.cycle.all.js

使用代码brian进行编辑:

脚本:

     function load(div, of)
{
     $(div).load(of, function() {
});  
}
$('.botones-lateral-j').click(function () {
    var $this = $(this) // cache jquery `this` object so we don't need to reinstantiate it every time we use it

    var script = $this.data('script');
    var target = $this.data('target');
    var button = $this.data('button');

    console.log(script, target, button); // log data to make sure it's correct, remove before deployment

    switch (button) {
        case 'lateral':
            $(target).load(of, function() {    
               twttr.widgets.load();
            }).hide().fadeIn("slow"); 
            break;
        case 'button2':
            $(target).load(of, function() {    
               FB.XFBML.parse(document.getElementById('div-d'));
               twttr.widgets.load();
            }).hide();
            break;
        case 'button3':
            $.getScript("jquery.cycle.all.js", function(data, textStatus, jqxhr) {
                console.log(data); // Data returned
                console.log(textStatus); // Success
                console.log(jqxhr.status); // 200
                console.log("Load was performed.");
            });
        break;
    }
});

按钮:

<a href="#inicio" class="botones-lateral-j" data-script="<?php $_SERVER['DOCUMENT_ROOT']?>/dis/lateral-2.php" data-target="#lateral" data-button="lateral1">SIG</a>

我尝试了淡入效果,看它是否删除了数据按钮lateral1 它不起作用,甚至不改变div :(

2 个答案:

答案 0 :(得分:1)

在案件之间放置造型。

function load(styleType) {
    switch (styleType) {
        case "button1":

        break;

        case "button2":

        break;

        case "button3":

        break;
    }
}

不要忘记自己输入参数。

如果您有任何问题,请发布。

答案 1 :(得分:1)

编辑 - 包括事件侦听器并使用echo $message; //fixed by type cast to int $userAmt = (int) " 20 "; $points = (int) "10"; if($userAmt > $points ){ //<- attackers are circumventing $message = "You do not have enough points"; } else if ($userAmt < 1 || $userAmt > 20){ //<-attackers are not circumventing $message = "Must be between 1 and 20"; } else { $message = "winner"; } echo $message; 属性而不是交换机中的脚本。

HTML:

data-*

JS:

<a href="#inicio" class="temas-deco-d" data-script="road.php" data-target=".div-d" data-button="button1">ROAD</a>
<a href="#inicio" class="temas-deco-d" data-script="street.php" data-target=".div-d" data-button="button2">STREET</a>
<a href="#inicio" class="temas-deco-d" data-script="house.php" data-target=".div-d" data-button="button3">HOUSE</a>