无法访问Clicked元素值

时间:2013-11-22 09:23:20

标签: jquery kendo-ui kendo-grid javascript

我想显示一条警告消息,该消息应该包含我们点击的元素的值,为此我写了一些代码,

 <script type="text/javascript">
    function filterProducts() {
        var clicked = this;
        alert($(clicked).val());
        return {
            Reference: $(this).val()
        };
    }


</script>


@(Html.Kendo().DropDownList()
    .Name("ReferenceValue") //The name of the dropdownlist is mandatory. It specifies the "id" attribute of the widget.
    .DataTextField("ValidValue") //Specifies which property of the Product to be used by the dropdownlist as a text.
    .DataValueField("ReferenceValidValueID") //Specifies which property of the Product to be used by the dropdownlist as a value.
    .BindTo(Model)
            .DataSource(source =>
            {
                source.Read(read =>
                {
                    read.Action("GetReferenceValidValue", "GetData").Data("filterProducts"); //Set the Action and Controller name
                })
                .ServerFiltering(true); //If true the DataSource will not filter the data on the client.
            })
    .SelectedIndex(0) //Select first item.
)

但是在点击Dropdown时,它没有显示在函数“filterProduct”中写入的警告消息。

在那个时候它会给出某种异常,

Cannot call method 'toLowerCase' of undefined

1 个答案:

答案 0 :(得分:0)

function filterProducts() {
        var clicked = this;// this property not acccess  like this 
        alert($(clicked).val());
        return {
            Reference: $(this).val()
        };
    }

你可以尝试

$("selector").click(function(){
 ^^^^here you can write $("button") and etc as your requirement
            var clicked = this;
            alert($(clicked).val());
            return {
                Reference: $(this).val()
            };

}):