【问题标题】:in jqgrid select, i'd like to set another edit form field to the selected value then set the selected value to selected label在 jqgrid 选择中,我想将另一个编辑表单字段设置为选定的值,然后将选定的值设置为选定的标签
【发布时间】:2011-11-14 05:16:57
【问题描述】:

在类型为“select”的 jqgrid 编辑表单字段中,我正在使用编辑选项设置另一个具有所选值(发送到服务器的值)的编辑表单字段:

dataEvents:[{type:'change',fn:function(e){$('input#STID').val(this.value);}}]}

然后我想用选定的标签替换选定的值。我认为通过将语句添加到 dataEvents 函数可以实现以下操作,但事实并非如此:

this.value = this.label;

如何做到这一点?

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    “更改”事件this(如e.target)内部是DOM 元素HTMLSelectElement。所以$('option:selected', this).text()$('option:selected', e.target).text() 将从所选选项中获取文本。

    您不应修改HTMLSelectElementvalue 属性,而只需将所选选项的文本用作<input> 编辑字段的输入:

    dataEvents: [
        {
            type: 'change',
            fn: function () {
                $('input#STID').val($('option:selected', this).text());
            }
        }
    ]
    

    【讨论】:

    • so.. $('input#STID').val($('option:selected', this).value());会得到所选选项的值吗?
    • @NelsonM: $('option:selected', this).value() 是所选选项的值,$('option:selected', this).text() 是所选选项的文本。 $('option:selected', this).value() 的值可以以更短的方式获得(就像您之前使用的那样),但不是文本。
    猜你喜欢
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多