简体   繁体   English

调用了jquery click事件,但未执行某些DOM操作

[英]jquery click event called but some of the DOM manipulation does not get executed

I have a single html page the id's and class'es are empty. 我有一个HTML页面,其ID和类为空。 They are filled by the data returned by ajax get request. 它们由ajax get请求返回的数据填充。 So, users see the app as signin page, home page, offer page, and events page. 因此,用户将应用视为登录页面,主页,商品页面和事件页面。 On successful login, they see a home page. 成功登录后,他们会看到一个主页。 Only after the successful login, users will be able to see the footer, which are the image icons for home, offers and events. 只有成功登录后,用户才能看到页脚,它们是主页,商品和事件的图像图标。 The elements inside the html page is shown or hidden based on what page user want to navigate by clicking on the image icons. 根据用户想要通过单击图像图标导航的页面来shown or hidden html页面内的元素。

My issues are: If I already have offers, and events , then navigating to these pages from any other page will not be a problem, but if any one of these is empty , then navigating to the page (that has some content) from an empty content page, some of the jquery manipulations do not occur on click event . 我的问题是:如果我already have offers, and events ,那么从任何其他页面导航到这些页面都不会有问题,但是如果其中任何one of these is empty ,则从一个页面导航到该页面(包含一些内容)。在内容页面为空的情况下,某些click event do not occur在jQuery操作上。 And, I am trying to find out why this is happening? 而且,我试图找出为什么会这样?

Say, from empty offer page to event page with some events already in the database, The events content gets populated, but 假设,从空的报价页面到事件页面,其中数据库中已经有一些事件,则将填充事件内容,但是

  • The headers will not change. 标头将保持不变。 The headers will still say offers, but the content is of events. 标头仍然会显示要约,但内容是事件。
  • The image icons would not change. 图像图标不会改变。 I have normal and click-over images. 我有普通图片和点击后图片。 The click-over image will still be of offer, not the event. 点击后的图片仍将提供,而不是活动。

But, if both of these pages are either empty or have some data, 但是,如果这两个页面都为空或有一些数据,

  • The headers change normally. 标头通常会更改。
  • The image icons change normally. 图像图标正常更改。

Below is the jquery click event script 以下是jquery click事件脚本

$(".fevent").live('click', function(){
    $.ajax({
        url: 'http://192.168.3.100:3000/events.json?playerid='+$('#playerid').html(),
        type: "get",
        cache: false,
        success: function(data) {   
            //keep the element is always empty first before loading anything into it
            $('#events_table').html('');

            //fill the table with offers
            $.each(data, function(index, event) {
                if (event['read'] == 1){
                    $('#events_table').append('<tbody><tr class="event_list"><td class="spacer"><img alt="Spacer" src="css/images/spacer.png"></td><td class="image"><img height="60px" src="css/images/'+ event['code'] +'e.png" width="60px"></td></td><td class="description"><h3>'+ event['description']+ '</h3><p>Start Date: '+ month[(new Date(event["startdate"])).getMonth()] + ' ' + (new Date(event["startdate"])).getDate() +', '+ (new Date(event["startdate"])).getFullYear() +'</p><p>End Date: '+ month[(new Date(event["enddate"])).getMonth()] + ' ' + (new Date(event["enddate"])).getDate() +', '+ (new Date(event["enddate"])).getFullYear() +'</p></td></tr>');
                }
                else {
                    $('#events_table').append('<tbody><tr class="event_list_unread"><td class="spacer"><img alt="Spacer" src="css/images/spacer.png"></td><td class="image"><img height="60px" src="css/images/'+ event['code'] +'e.png" width="60px"></td></td><td class="description"><h3>'+ event['description']+ '</h3><p>Start Date: '+ month[(new Date(event["startdate"])).getMonth()] + ' ' + (new Date(event["startdate"])).getDate() +', '+ (new Date(event["startdate"])).getFullYear() +'</p><p>End Date: '+ month[(new Date(event["enddate"])).getMonth()] + ' ' + (new Date(event["enddate"])).getDate() +', '+ (new Date(event["enddate"])).getFullYear() +'</p></td><td class="mark_as_read"><img alt="Unread1" class="unread" src="css/images/unread1.png"><p class="read" style="display:none">events/'+event["id"]+'</p></td></tr></tbody>');    
                    $('#total_bulbs').html(event['total_bulbs']);
                }
                count_bulbs = count_bulbs + parseInt(event['total_bulbs']);
            });

            //working fine
            $('#signin_content').hide();
            //working fine
            $('#signin_header').hide();
            //working fine
            $('.submitimg').hide();
            //working fine
            $('#player_header').show();
            //working fine
            $('#player_content').hide();
            //working fine
            $('#offers_content').hide();
            //working fine
            $('#footer').show();
            //working fine
            $('#events_content').show();

            //*******************this is the header and it is not changing**************************
            $('.alignleft').html('Events');

            $('.fhome').html('<img alt="Home" class="footer_img" src="css/images/home.jpg" width="100%">');
            $('.foffer').html('<img alt="Offers" class="footer_img" src="css/images/offers.jpg" width="100%">');

            //****************this is not changing also****************************
            $('.fevent').html('<img alt="Events" class="footer_img" src="css/images/eventsover.jpg" width="100%">');

        }//end of fevent success
    });//end of fevent ajax
    $( "[data-position='fixed']" ).fixedtoolbar( 'updatePagePadding' );
});//end of fevent

The following is my header: 以下是我的标题:

 <div data-role="header" data-tap-toggle="false" data-position="fixed" id="player_header" style="display:none">
    <img alt="Header" src="css/images/header.jpg" width="100%" class="headerimg">
    <div class="ui-bar">
        <h3 class="alignleft"></h3>

        <div class="alignright" id="home_notification"><img alt="Redlight" height="31px" src="css/images/redlight.png" class="notification_img" width="35px"></div>
        <div style="clear: both;"></div>

    </div>
</div>

and the following is my footer 以下是我的页脚

 <div id="footer" style="display:none">
    <ul>
        <li class="fhome"><img alt="Home" class="footer_img" src="css/images/home.jpg" width="100%"></li>
        <li class="foffer"><img alt="Offers" class="footer_img" src="css/images/offers.jpg" width="100%"></li>
        <li class="fevent"><img alt="Events" class="footer_img" src="css/images/events.jpg" width="100%"></li>
        <li class="fpromo"><img alt="Promo" class="footer_img" src="css/images/promo.jpg" width="100%"></li>
        <li class="fnews"><img alt="News" class="footer_img" src="css/images/news.jpg" width="100%"></li>
    </ul>

</div>

. live is deprecated.. try using . live已弃用。尝试使用。 on instead.. ,而不是..

$(function() {
    $(".fevent").on('click', function(){

});

Also make sure your code is inside the DOM ready event.. Check in the browser whether you see a request being sent in the first place by hitting the F12 button 还要确保您的代码在DOM ready事件中。.在浏览器中,通过按F12按钮检查是否首先看到了发送的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM