admin管理员组

文章数量:1287931

I am using the kendo dropdownlisthelper, which has a change event, see below

@(Html.Kendo().DropDownListFor(m => m)
        .Name(Model.Name)
        .Text(Model.PlaceHolder)
        .BindTo(Model.ListItems)
        .DataTextField("Text")
        .DataValueField("Value")
        .Enable(Model.Enabled)
        .Events(e =>
        {
            e.Change("change");
        })
        .HtmlAttributes(new {@id= Model.ID.ToString() })

The function that handles the change event:

function change(e) {
    var dataItem = this.dataItem(e.item);
    console.log("selected values (" + dataItem.Text + " : " + dataItem.Value + ")");
}

SO this displays the selected value in the console.

The Question: I'm struggling to work this out, but how do i display the Name and ID of the parent element that made the call to the change event(in this case the drop-down list).

So basically i want to display these values: - Name attribute of the dropdown list - Id attribute of the dropdown list

Cheers!

I am using the kendo dropdownlisthelper, which has a change event, see below

@(Html.Kendo().DropDownListFor(m => m)
        .Name(Model.Name)
        .Text(Model.PlaceHolder)
        .BindTo(Model.ListItems)
        .DataTextField("Text")
        .DataValueField("Value")
        .Enable(Model.Enabled)
        .Events(e =>
        {
            e.Change("change");
        })
        .HtmlAttributes(new {@id= Model.ID.ToString() })

The function that handles the change event:

function change(e) {
    var dataItem = this.dataItem(e.item);
    console.log("selected values (" + dataItem.Text + " : " + dataItem.Value + ")");
}

SO this displays the selected value in the console.

The Question: I'm struggling to work this out, but how do i display the Name and ID of the parent element that made the call to the change event(in this case the drop-down list).

So basically i want to display these values: - Name attribute of the dropdown list - Id attribute of the dropdown list

Cheers!

Share Improve this question asked Aug 15, 2016 at 11:01 MCSDMCSD 1512 silver badges12 bronze badges 2
  • What do you mean - "how do i display the Name and ID of the parent element that made the call " ? Please provide more details on what you whant to achive – Anton Commented Aug 15, 2016 at 13:54
  • Your answer below was useful and was the answer i was looking for. It would be interesting to know if there was a way to pass the entire model to the change event..hmm. – MCSD Commented Aug 15, 2016 at 14:57
Add a ment  | 

1 Answer 1

Reset to default 11

You can use this approach to get Id of element on which event have occured

function change(e) {
    var elementId = e.sender.element[0].id
}

本文标签: javascriptGet ID attribute from Kendo dropdownList change eventStack Overflow