-1

我是 jquery 的新手。我已将视图绑定到模型,并希望从模型的属性之一中读取值。但它没有显示。

@model OnlineEvaluation.ViewModel.DynamicContentViewModel
@{
    ViewBag.Title = "Dynamic Content";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <fieldset>
        @Html.HiddenFor(model => model.ContentId)
        @Html.HiddenFor(model => model.DurationInMinutes);
        @Html.DisplayFor(model => model.Content)        
        <input type="submit" value="Next" />
        <input type="text" readonly="true" id="timer1" class="timer" />
    </fieldset>
}

@section Scripts {

    <script type="text/javascript" >
        $(document).ready(function () {
            $(document).doit(function () {
                alert("Hi");
                var value = $("#DurationInMinutes").val();
                alert(value);
                return false;
            });
        });

    </script>

}

编辑:加载“timer1”文本框时,我需要读取该值。

@section Scripts {

    <script type="text/javascript">
        $(document).ready(function () {
            $('timer1').load(myFunction);
        });

        function myFunction() {
            alert("Hi");
            var value = $("#DurationInMinutes").val();
            alert(value);
        }
    </script>
}

当我运行上面的代码时,不显示警报消息框。

谢谢

4

2 回答 2

0

失去$(document).doit(function () { });.

$(document).ready(function () {
    alert("Hi");
    var value = $("#DurationInMinutes").val();
    alert(value);
    return false;
});
于 2013-10-21T10:09:51.113 回答
0

根据评论

I need to call one function once the Ready function is called
DoIt is not external plugin. It is just the custom function

只需调用您的函数

$(document).ready(function () {
    YourFunction(); //Call your function like this
});
于 2013-10-21T10:15:35.200 回答