The Click event invalidation problem after Ajax request data in Javascript-js

Source: Internet
Author: User
I have a list of data that has a click-to-expand effect. Since this list of data is used ajaxLoading, is ajaxAfter loading the clickTime does not work, I hope that the great God to help you see.
This is htmlThe data structure and page layout in

                        

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

jsThe following are the expansion click events and ajax requests in

phpdivsettings and data settings in the


  
    $value) {   $html .='';   $html .='

'.$value['desc'].'

'; $html .='

时间:'.date('Y-m-d', $value['updateTime']).' | 来源:'.$value['author'].' 展开

'; $html .='';}$result['html'] = $html;exit(json_encode($result));

I php have added the styles in the middle div ! But it just doesn't work.

Reply content:

I have a list of data that has a click-to-expand effect. Since this data list ajax is loaded, that is ajax , the time after loading click does not work, I hope that the great God to help you see.
This is the html data structure and page layout in

                        

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

消费者的信息会逐渐增多,如果有一个厂家,用更好的原料和工艺,就会迅速占领市场

时间:2016-05-24 | 来源:本站 展开

jsThe following are the expansion click events and ajax requests in

phpdivsettings and data settings in the


  
    $value) {   $html .='';   $html .='

'.$value['desc'].'

'; $html .='

时间:'.date('Y-m-d', $value['updateTime']).' | 来源:'.$value['author'].' 展开

'; $html .='';}$result['html'] = $html;exit(json_encode($result));

I php have added the styles in the middle div ! But it just doesn't work.

Thank you for inviting me. I've had this similar problem before, and it's also the result of the ajax() loaded data that invalidates the original effect. Here's how I handle it.

// 初始化数据的时候我也是这么写的$('.message-but').click(function(){    // code...});// ajax加载后click事件不执行,又改成这样$('.message-but').live("click",function(){    // code...});

After the online query to know that this live() actually and bind() almost the same use, are can give the future element binding corresponding trigger event, but there are still different. Both of you try and hope it helps you.

There's no live method after jquery1.9+.

We can write the previous version of jQuery1.9:

$("a").live("focus",function(){  

jQuery1.9 since live was deleted, it should be written like this:

$(document).on("focus","a",function(){  

I have a rough look at it, and if each of you list-data-detail is dynamically loaded through Ajax, then the event you started writing directly click doesn't work, and the DOM doesn't exist when you're bound to the event.
At this time, you need to use 事件委托 , in jQuery , that is

$('.list-data').on('click', '.open-detail', function() {    /// here goes the code});

That's all. With event delegates, the child element's event is bound to the parent element, and after the child element is clicked, the event bubbles to the parent element, which is responsible for capturing and then triggering the event by the parent element.

Dynamically loaded elements to perform a click can be like this

$(document).on('click','.message-but',function(){    // code...});
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.