简体   繁体   中英

jeditable dynamic maxlength

following up to this question: jquery select and use part of class name

i thought to use this way to dynamically assign a maxlength to the jeditable script (i assign a special class to each element startig with edit_* , where the star is the maxlength):

$("[class^='edit_']").editable('url', {
    id          : $(this).attr('id'),
    maxlength   : $("[class^='edit_']").on('click',function() {
            return $(this).attr('class').split(' ')[0].split('_')[1];
    }),
});

problem is that while the function itself works if used separately, it doesn't work inside the above script. I even tried to return a number manually (ex. return 2 ) and it works...what's the trick?

ok, for those who will be landing here...i solved this way:

$("[class^='edit_']").each( function() {
    var ml = $(this).attr('class').split(' ')[0].split('_')[1];
    $(this).editable('[url]', {
        [...]
        maxlength   : ml,
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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