开发者

JQuery live not working with Jqtransform select while adding dynamic controls

开发者 https://www.devze.com 2023-04-06 09:56 出处:网络
I have a functionality where we are adding a dynamic row while clicking a addrow button in a table. My problem is that I have to alert a message while changing my select list in the new row but its no

I have a functionality where we are adding a dynamic row while clicking a addrow button in a table. My problem is that I have to alert a message while changing my select list in the new row but its not working when we use Jquery live click. But its working for all other select boxes which are not dynamically added while using Jquery bind click. Can anybody give me a help to resolve this?

In my project we are using Jqtransform for formatting html 开发者_如何学Gocontrols.

What i have done so far is

    $('div.jqTransformSelectWrapper ul li a').live('click',function() {
        alert('message');}
    });


I have resolved this by modyfying the Jqtransform.js file by triggering the change event of the select list by doing the following. Actually its a bug regarding the Jqtransform.js

If you got to this post of mine you probably know what jqtransform is, and you are probably struggling with a dropdownlist's change event.

Reason why it is not working is due to the fact that jqtransform creates a dropdownlist using an unordered lists, then it hides your dropdownlist.

The fix is actually quite simple.

open your jquery.jqtransform.js file and find the following line:

/* Fire the onchange event */
if ($select[0].selectedIndex != $(this).attr('index') && $select[0].onchange) {
     $select[0].selectedIndex = $(this).attr('index');
     $select[0].onchange();
}

now simply add the following below that line:

/* Fire the change event */
if ($select[0].selectedIndex != $(this).attr('index')) {
     $select[0].selectedIndex = $(this).attr('index');
     $($select[0]).trigger('change');
}


Use jQuery delegate() instead. It's better than live for many reasons. Please use console.log() instead of alert() for debugging too!

$('div.jqTransformSelectWrapper ul li').delegate('a', 'click',function() {
        console.log('message');}
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消