【问题标题】:Get the ID/Name of Html.TextBox in the jquery select event of kendo AutoCompletekendo AutoComplete的jquery select事件中获取Html.TextBox的ID/Name
【发布时间】:2013-01-02 18:51:13
【问题描述】:

我有一个剃须刀页面,其中有一个 Kendo AutoComplete 控件,并且在其更改事件中我需要得到两件事:

  1. 该剑道自动完成控件的 ID
  2. 最近的文本框 ID

因为会有这两个控件的克隆。

这是我的代码:

function autocomplete_select(e) {
      var dataItem = this.dataItem(e.item.index());
      var txtbx = $(this).closest("input[type='text']");
      alert("Name==" + txtbx.attr('name'));
      alert("ID==" + txtbx.attr('id'));
      var tmp = $(this).closest("div.mf_form_field").find("input[type='text']").attr('id');
      alert(tmp);
      }

@(Html.Kendo().AutoComplete()
 .Name("ACDD")
 .BindTo((IEnumerable<String>)strActionCodes)
 .Events(e => e.Select("autocomplete_select")))
  </div>
<div>@Html.Label("Action Value")</div>
<div>@Html.TextBox("Value",null, new { style = "width : 105px"})</div>

这里没有返回文本框 ID 的警报,我无法获得剑道自动完成的名称/ID。

【问题讨论】:

    标签: jquery asp.net-mvc-3 kendo-ui


    【解决方案1】:

    自动完成的 id 是这样检索的:

    function onChange(e){
        alert(this.element.attr('id'))
    }
    

    可以像这样检索最接近文本框的(在您的情况下不是 closest 而是 next - 检查 jQuery 文档以了解这两者之间的区别)。

    function onChange(e){
        alert(this.wrapper.next('input[type="text"]').attr('id'))
    }
    

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 2013-03-22
      • 1970-01-01
      相关资源
      最近更新 更多