如何在jquery.sumoselect插件选择列表中添加更多元素?

时间:2015-06-05 11:11:15

标签: javascript jquery sumoselect.js

我想在列表中添加多个选择复选框的更多元素,但是当我添加更多元素时,它们会出现在列表之外。

这是我想要输入的代码:

Sub sortingP8(Item As Outlook.MailItem)
    Dim olkAtt As Outlook.Attachment
    'Check each attachment
    Dim totalSize As Double
    Dim containsZip As Boolean
    Dim wrongExt As Boolean
    totalSize = 0
    containsZip = False
    wrongExt = False
    somethingWrong = False
    Set ns = Application.GetNamespace("MAPI")
    Set nonIngFolder = ns.Folders("Pqweeeq@asdasd.es").Folders("Non-ingestible Items")
    Set ingFolder = ns.Folders("Pqweeeq@asdasd.es").Folders("Ingestible Items")
    Set zipFolder = ns.Folders("Pqweeeq@asdasd.es").Folders("ZIP files")

    For Each olkAtt In Item.Attachments
        Dim extension As String
        extension = Right(LCase(olkAtt.FileName), 4)
        'If the attachment's file name ends with .zip
        totalSize = totalSize + olkAtt.Size

        If extension <> ".ppt" And extension <> ".doc" And extension <> ".pdf" And extension <> ".jpg" And extension <> ".zip" Then
            wrongExt = True
        End If
        If extension = ".zip" Then
            containsZip = True

        End If
    Next
    If (wrongExt = True Or totalSize > 10000000) Then
        Item.Move nonIngFolder
        somethingWrong = True
    End If
     If (containsZip = True And somethingWrong = False) Then
        Item.Move zipFolder
        somethingWrong = True
    End If
     If (somethingWrong = False) Then
        Item.Move ingFolder
    End If
    Set olkAtt = Nothing
End Sub

我希望select选项显示如下:

Screenshot

1 个答案:

答案 0 :(得分:0)

根据您的意见,如果您想将其置于列表中,您可以按以下方式执行:

将其作为第一个元素:

<强> DEMO

$('.spr').on('click',function(){
    if($('.input-add-list').val().trim()!=='')
    {
        $('<option value="'+$('.input-add-list').val().trim()+'">'+$('.input-add-list').val().trim()+'</option>').insertBefore('.SlectBox option:first');
    }
});

将其作为最后一个元素

<强> DEMO

$('.spr').on('click',function(){
    if($('.input-add-list').val().trim()!=='')
    {
        $('.SlectBox').append('<option value="'+$('.input-add-list').val().trim()+'">'+$('.input-add-list').val().trim()+'</option>');
    }
});
  

如果可能,请将标签Add更改为按钮

<强>更新

使用您的原生plugin方法,如下所示:

<强> DEMO

$('.spr').on('click',function(){
    if($('.input-add-list').val().trim()!=='')
    {
        $('select.SlectBox')[0].sumo.add($('.input-add-list').val().trim());
    }
});