jQuery X-editable 从选择中传递选定的文本

jQuery X-editable pass selected text from select

本文关键字:文本 X-editable 选择 jQuery      更新时间:2023-09-26

有一个关于x-Editable select的快速问题。

我想在选择中获取所选项目的文本并将其传递给 .Net 处理程序,以便以后可以将其添加到审核表中。

有人知道我该怎么做吗?

这是我目前拥有的:

锚代码:

<a class='editable' data-type='select' data-name='statusid' data-pk='1027' data-params='{"original": "In Progress"}' data-value='2' data-source='handlers/getHDMLists.ashx?l=1' id='status'>In Progress</a>

和jQuery Post:

$('#status').editable({
                showbuttons: true,
                url: function (params) {
                    return $.ajax({
                        type: 'POST',
                        url: 'handlers/putHDMTicketDetails.ashx?ac=1',
                        data: params,
                        params: '{"new": "' + $(this).text() + '"}' ,
                        async: true,
                        cache: false,
                        timeout: 10000,
                        success: function (response) {
                            if (response != null) {
                                if (response.msg == "SUCCESS") {
                                    $.gritter.add({
                                        title: 'Update Successful',
                                        text: 'Support ticket details update was successful.',
                                        class_name: 'gritter-success gritter-center gritter-light'
                                    });
                                } else {
                                    $.gritter.add({
                                        title: 'Something went wrong!',
                                        text: 'There seems to have been an error with your requested update, please try again and if you continue to receive this message please contect your site administrator.',
                                        class_name: 'gritter-error gritter-center'
                                    });
                                }
                            } else {
                                $.gritter.add({
                                    title: 'Something went wrong!',
                                    text: 'There seems to have been an error with your requested update, please try again and if you continue to receive this message please contect your site administrator.',
                                    class_name: 'gritter-error gritter-center'
                                });
                            }
                        },
                        error: function () {
                            $.gritter.add({
                                title: 'Something went wrong!',
                                text: 'There seems to have been an error with your requested update, please try again and if you continue to receive this message please contect your site administrator.',
                                class_name: 'gritter-error gritter-center'
                            });
                        }
                    });
                }
            });

如您所见,我可以通过在 anochor 中使用数据参数占位符来获取原始文本,但我试图使用 $(this).text() 获取新选择的文本,但它被忽略了:-(

任何帮助都会很棒。

奥兹

好的,

所以经过一些跟踪,事实证明X-editable提供的输入元素没有可用的ID或名称,但是,它们被包装在一个带有可编辑输入类的div中。

将上面的代码行从:

url: 'handlers/putHDMTicketDetails.ashx?ac=1',

url: 'handlers/putHDMTicketDetails.ashx?ac=1&new=' + $('.editable-input').find(':selected').text(),

很好地对问题进行排序,并在所有输入元素中保持一致。

奥兹