JQuery Simple Combobox(scombobox)获取发短信的字符串
问题描述:
我有一个scombobox和每次用户按下btnAdd
按钮时出现的文本字段。JQuery Simple Combobox(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%" /> '
+ combo.prop('outerHTML') + ' '
+ '<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获取输入的文本?
答
我通过添加$("#" + index).scombobox({ fullMatch: true, invalidAsValue: true })
找到了我的问题的答案,但它似乎只是在IE上工作的方式。为了$("#" + i + " .scombobox-display").val()
它工作!
答
这是我第一次听到scombobox的,有可能是更好的解决方案,但检查这个环节http://jsfiddle.net/alpenzoo/7vpf1axs/
$("#combo-02").find("input").val()
似乎正确地从scombobox返回数据。