jquery - 使用jquery tablesorter插件,有一个下拉框,其中包含选定的项目

标签 jquery ajax jquery-plugins tablesorter

我创建了一个表,允许用户编辑/更正数据。该表填充得很好,并且是为了使该表尽可能易于使用。我添加了下拉框,当他们需要更改任何信息时可以从中进行选择。

JS 文件是:

for(y=0;y<data.defect2.length; y++) {
    myselectoptions += '<option value="'+data.defect_id[y]+'"' +
        (data.defect_id[y]==data.defect[y] ? ' selected="selected"' : '') + 
        '>'+data.defect2[y]+'</option>';
}

if (data.isbn2 === null) {
    $("#inventoryUpdate").append('<tr><td>No Records Found</td></tr>');
} else {
    for(var x=0;x<data.isbn2.length;x++) {
        $("#inventoryUpdate").append('<tr><td id="tableSKU">'+data.sku[x]+'</td><td id="tableISBN">'+data.isbn2[x]+
        '</td><td id="tableQuantity">'+data.quantity[x]+
        '</td><td><select id="tableDefect">'+myselectoptions+//'" selected="'+data.defect[x]+'">'+myselectoptions2+
        '"</select></td><td><select id="tableSource">'+sourceoptions+
        '"</select></td><td><select id="tableFeature">'+featureoptions+
        '"</select></td><td><select id="tableWater">'+wateroptions+
        '"</select></td><td><select id="tableLocation">'+locationoptions+
        '"</select></td><td><input type="text" id="tableProcessDate" value="'+data.processDate[x]+
        '"/></td><td><select id="tableBookType">'+bookoptions+
        '"</select></td><td><select id="tableCreatedBy">'+useroptions+
        '"</select></td><td><select id="tableModifiedBy">'+useroptions+
        '"</select></td></tr>');
    }

    $("#inventoryUpdate").trigger("update");
}

这一切都有效,只是我不能将其默认为数据库查询中选定的项目。所选项目是表中最后一项的值。 关于如何实现这一点有什么想法或者是不可能做到吗?

最佳答案

我建议不要在初始渲染期间尝试添加 selected 属性,而是建议在之后运行它。像这样的事情:

var selectedValue = 'option[value="'+data.defect_id[y]+'"]';
$('#tableDefect').find(selectedValue).attr("selected",true).end();

关于jquery - 使用jquery tablesorter插件,有一个下拉框,其中包含选定的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13826207/

相关文章:

jquery - 使用 jQuery 和 AJAX 时我应该捕捉按钮单击或表单提交吗?

Jquery 十进制掩码插件 - 对象不支持此属性

javascript - 通过 Jquery 正确验证输入框

PHP + AJAX 在查询数据库时不产生结果

jquery - Bootstrap 导航栏切换按钮隐藏在移动设备上直到滚动(iOS)

jquery - 如何更改 jQuery pickadate 主题

php - 使用 PHP 从 Bootstrap Select 获取多选数据

jquery - chrome 中 iframe 内容的分页符

javascript - 如何使用 AJAX 和 jQuery 正确检查包含 "/+=@#^"的密码

jquery - jquery ajax函数中的多个数据变量