weixin_33709219 2017-11-07 14:59 采纳率: 0%
浏览 43

点击触发功能

I have a series of DIVs like this:

<div class="a" onclick="Test();"></div>
<div class="b" onclick="Test();"></div>
<div class="c" onclick="Test();"></div>
...

function Test(){
...
$.ajax({
   type: "POST",
   url: url,
   data: "somedata=" + somedata,
   contentType: 'application/x-www-form-urlencoded; charset=utf-8',
   dataType: "html",
   success: function (msg) {           
      var owl = $('.carousel-Class');
      owl.trigger('destroy.owl.carousel');
      owl.owlCarousel({
         ...
      })  
}

and I want trigger this function on page load on a specific div (I.E. div with class 'b'):

$(document).ready(function(){
    $(".b").trigger('click');
})

The result is that the Owl Carousel items don't appear correctly, they have different size than they should have. For appear correctly I need to do an extra click on the DIV.

Any idea?

  • 写回答

1条回答 默认 最新

  • 衫裤跑路 2017-11-07 15:19
    关注

    Why simulate the trigger and not just call the function Test() on your ready() function.

    Something like this:

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

    However it seems you have a concurency problem, try putting:

    async: false
    

    as a parameter of your ajax call to confirm it.

    评论

报告相同问题?

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上