JQuery Simple Combobox(组合框)获取文本字符串

标签 jquery combobox

每次用户按下 btnAdd 按钮时,我都会出现一个 scombobox 和一个文本字段。

$("#btnAdd").bind("click", function () {
    index++;
    var div = $("<div />");
    div.html(GetDynamicTextBox(''));
    $("#AddContainer").append(div);
    $("#" + index).scombobox({ fullMatch: true });
    var completedField = true; //variable to see if all fields (values ones) are completed - if no not allow to save changes
    //check if each text field for each setting has value
    $("input[name=DynamicTextBox]").each(function () {
        if ($(this).val() == "")
            completedField = false;
    });
    if (completedField == false)
        document.getElementById("AddBtn").disabled = true;
    else
        document.getElementById("AddBtn").disabled = false;
});

$("body").on("click", ".remove", function () {
    $(this).closest("div").remove();
    var ddlId = $('[id*=hfDDLId]').val();
    $('[id$=ddl' + parseInt(ddlId) + ']').remove();
    $('[id*=hfDDLId]').val(parseInt($('[id*=hfDDLId]').val()) - 1);
    var previousDropDownId = $('[id*=hfDropDownIds]').val();
    //$('[id*=hfdropdownids]').val(resultids);
    if (document.getElementById("AddContainer").innerHTML == "")
        document.getElementById("AddBtn").disabled = true;
    else {
        var completedField = true; //variable to see if all fields (values ones) are completed - if no not allow to save changes
        //check if each text field for each setting has value
        $("input[name=DynamicTextBox]").each(function () {
            if ($(this).val() == "")
                completedField = false;
        });
        if (completedField == false)
            document.getElementById("AddBtn").disabled = true;
        else
            document.getElementById("AddBtn").disabled = false;
    }
});

function GetDynamicTextBox(value) {

var combo = $('<select list="' + index + '" name="' + index + '"><datalist style="font-size:150%; width:50%"></select>').attr("id", index).attr("name", index).attr("runat", "server").attr("class", "class combos").attr("required", "required");

$.each(settingsListAry, function (i, el) {
    combo.append("<option value=" + el + ">" + el + "</option>");
});

return '<input type="button" value="-" class="remove btn btn-danger"  style="font-size:75%" />&nbsp'
+ combo.prop('outerHTML') + '&nbsp'
+ '<input name = "DynamicTextBox" class="dtb" type="text" value="' + value + '" required style="line-height: 0; width:30%" onkeyup="allHaveText()"/>'
+ '<div style="clear:both"></div>'

}

我的问题是,当用户键入新文本(不是选项中的文本)时,当我尝试获取键入的字符串 $("#"+ i).scombobox('val') 我只收到空字符串。

可以从 scombobox 中获取键入的文本吗?

最佳答案

这是我第一次听说 scombobox,可能有更好的解决方案,但请检查此链接 http://jsfiddle.net/alpenzoo/7vpf1axs/

$("#combo-02").find("input").val()

似乎可以正确地从 scombobox 返回数据。

关于JQuery Simple Combobox(组合框)获取文本字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46713951/

相关文章:

GWT - 如何添加一个简单的组合框

wpf - 禁用可编辑组合框中的鼠标滚轮作为 ItemTemplate

java - 如何浏览枚举类?

javascript - 如何将表格从网页导出到 Excel

php - 使用Jquery与数据库进行验证

javascript - 使用 javascript 处理表单的问题

listview - JavaFX 2 中的奇怪控件宽度?

mysql - 在 ComboBox.Item 中隐藏部分 String.Format

javascript - 当输入仍然集中时,jquery 代码不执行

jquery - 用 css 或 jquery 打开和关闭框(div)