jQuery - Append a Value to a INPUT, keeping it a Comma Delimited list

后端 未结 4 847
Happy的楠姐
Happy的楠姐 2020-12-16 14:42

I have an input like follows:


I\'d like to be able to append a value to th

4条回答
  •  自闭症患者
    2020-12-16 15:15

    $('#attachment-uuids').val(function(i,val) { 
         return val + (!val ? '' : ', ') + '66666';
    });
    

    EDIT: As @mkoryak noted, I'm doing an unnecessary negation of val in the conditional operator. It could be rewritten without the ! as:

    (val ? ', ' : '')
    

提交回复
热议问题