我有一个剃刀页面,那里有一个剑道自动完成控件和它的变化事件,我需要得到两个东西:
- 剑道自动完成控件的Id
- 最近的文本框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。
自动完成的id是这样获取的:
function onChange(e){
alert(this.element.attr('id'))
}
最接近的文本框(在您的情况下不是最接近的,而是下一个 -检查这两者之间的差异jQuery文档)可以像这样检索。
function onChange(e){
alert(this.wrapper.next('input[type="text"]').attr('id'))
}