[英]onchange event to html.editfor
I have an input box that is created in razor using Html.EditorFor. 我有一个使用Html.EditorFor在剃刀中创建的输入框。
@Html.EditorFor(model => model.person.Person.FirstName)
I would like to add a change event to this box so that some code will trigger if the value changes. 我想在此框中添加一个更改事件,以便在值更改时触发某些代码。
I have tried this jquery: 我试过这个jquery:
$('#person_Person_FirstName').change(function () {
alert($(this).val());
}).change();
But I'm not getting anything. 但是我没有得到任何东西。
Does anyone have any ideas? 有没有人有任何想法?
Try this code: 试试这段代码:
$(function() {
$(document).on('change','#person_Person_FirstName', function() {
alert($(this).val());
});
});
If that is the actual id of that rendered element, then doing this should work: 如果那是该渲染元素的实际id,那么这样做应该有效:
jQuery(function($) {
$('#person_Person_FirstName').change(function () {
console.log( this.value );
}).change();
});
添加$(document).ready(function(){ //...above code here })
工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.