简体   繁体   English

可编辑动态最大长度

[英]jeditable dynamic maxlength

following up to this question: jquery select and use part of class name 接下来的问题: jQuery选择并使用部分类名

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): 我认为可以使用这种方式为可编辑脚本动态分配maxlength(我为每个元素startig分配一个特殊类,其中edit_* ,其中star为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? 我什至尝试手动返回一个数字(例如return 2 ),它的工作原理是什么?

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,
    });
});

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

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