var attachmentids = $("input[name='attachmentid']").map(function(){return $(this).val()}).get().join(",");

  如果是多个值,自动用 逗号 合并 例如:4,5