【问题标题】:Input (Text field) --- Focus() not working输入(文本字段)--- Focus() 不起作用
【发布时间】:2013-02-26 08:46:58
【问题描述】:

有很多关于focus() 的问题,但我找不到任何可行的解决方案。

我正在使用带有一些列的 Slick Grid:

{id: "Something", name: "Something", field: "Something", width: 200, editor: Slick.Editors.Text }

var ResourcesGridOptions = {
        editable: true,
        enableCellNavigation: true,        
        enableColumnReorder: false,
        autoEdit: false
    };   

我实现了一个按钮来创建新行。现在我想自动聚焦输入文本。此时我可以设置“编辑”模式,但focus() 不起作用。

也许有人可以帮助我。

在我正在使用的 Chrome Javascript 控制台中:

$($('.slick-cell:eq(2)').dblclick().find('input')[0]).select().val("").focus()

控制台返回:

[<input type="text" class="editor-text" value="">]

更新 1

我尝试在此输入字段中添加一个“Id”,然后直接将其聚焦....没有用。

$($('.slick-cell:eq(2)').dblclick().find('input')[0]).attr('id', 'Something')
$('#Something').focus()

返回:[&lt;input type="text" class="editor-text" value="" id="Something"&gt;]

【问题讨论】:

  • +1,是的,即使在我的回答帖子 here 中也包含 1 行代码来动态创建输入元素,但是当我尝试聚焦它时,它就不起作用(聚焦)。
  • 我认为第一个$ 是不需要的。写$('.slick-cell:eq(2)').dblclick().find('input').eq(0).attr('id', 'Something')

标签: jquery focus textfield slickgrid


【解决方案1】:

尝试在添加按钮的点击事件上调用以下函数,

function AddNewRow() {
var dataLength = dataView.getLength();
//dataView.addItem({ "Id": -1 });
//dataView.refresh();
grid.gotoCell(dataLength, 0, true);
}

【讨论】:

    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-11
    • 2016-12-29
    • 2018-03-03
    • 2011-02-15
    • 2020-03-26
    相关资源
    最近更新 更多