-1

我正在尝试将 jsfiddle 创建转移到我的网站,但我无法这样做。这是它的链接:

http://jsfiddle.net/mDc7p/213/

/* 
    Eventbrite Examples - organizer event list

    If you copy this code, please set your own API Key in the example below.
    You can request one here: http://www.eventbrite.com/api/key
*/

Eventbrite({'app_key': "HSMTSI2CUDKAXFTXX2"}, function(eb){

    // define a few parameters to pass to the API
    // Options are listed here: http://developer.eventbrite.com/doc/organizers/organizer_list_events/
    var options = {
        'id'    : "1667880002"
    };

    // provide a callback to display the response data:
    eb.organizer_list_events( options, function( response ){
        $('.event_list').html(eb.utils.eventList( response, eb.utils.eventListRow ));
    });
});

我尝试将标签内关闭的 javascript 代码添加<script type="text/javascript"></script>到我的 header.php、footer.php 和模板文件的底部(我在该特定页面上使用的那个,但它不起作用。添加 javascript 代码后,我<div class="event_list"></div>在页面内容区域内添加,因为这是我希望代码工作但它不工作的地方。我将 jquery 库包含在 header.php 文件中的“head”标签内。我还尝试了 onLoad 方法,方法是添加代码到 javascript 的顶部,但遗憾的是,它不起作用。请帮助我。

PS 我的网站正在运行 Wordpress。

4

2 回答 2

2

您是否将其包装在 document.ready 中?您的 jQuery 不会作用于加载时不存在的元素。

$(document).ready(function() {
    ...
});

或速记

$(function() {
    ...
});
于 2013-03-18T16:29:05.800 回答
2

小提琴设置为在 DOM Ready 上运行的代码。因此,您需要将 JavaScript 部分中的代码包装在 onready 调用中。

<script>
$(function() {

    /* 
        Eventbrite Examples - organizer event list

        If you copy this code, please set your own API Key in the example below.
        You can request one here: http://www.eventbrite.com/api/key
    */

    Eventbrite({'app_key': "HSMTSI2CUDKAXFTXX2"}, function(eb){

        // define a few parameters to pass to the API
        // Options are listed here: http://developer.eventbrite.com/doc/organizers/organizer_list_events/
        var options = {
            'id'    : "1667880002"
        };

        // provide a callback to display the response data:
        eb.organizer_list_events( options, function( response ){
            $('.event_list').html(eb.utils.eventList( response, eb.utils.eventListRow ));
        });
    }

);    
});
</script>
于 2013-03-18T16:29:36.500 回答