如何参数传递给jQuery的的document.ready()函数(ASP.NET MVC,C#) [英] How to pass parameters to jQuery document.ready() function (ASP.NET MVC, C#)
本文介绍了如何参数传递给jQuery的的document.ready()函数(ASP.NET MVC,C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一个参数传递给jQuery的的document.ready()函数从我的观点:
I would like to pass a parameter to the jQuery document.ready() function from my View:
$(document).ready(function (parameter){
$('select[name=Product]').val(parameter);
});
我怎么能火从我查看事件和传递参数?我使用剃须刀作为视图引擎。
感谢
推荐答案
您不能。该功能的document.ready不带参数。例如,您可以定义此参数为您的视图一个全局变量:
You can't. The document.ready function doesn't take parameters. You could for example define this parameter as a global variable in your view:
<script type="text/javascript">
var model = @Html.Raw(Json.Encode(Model));
</script>
,然后在独立的JavaScript文件中使用这个全局变量:
and then in your separate javascript file use this global variable:
$(function() {
$('select[name=Product]').val(model.SomeProperty);
});
这篇关于如何参数传递给jQuery的的document.ready()函数(ASP.NET MVC,C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文