【发布时间】:2016-08-26 04:24:30
【问题描述】:
我是一般编程的新手,尤其是 jquery。我正在构建一个 ASP MVC 项目,该项目将以下插件用于星级评分系统:
https://github.com/kartik-v/bootstrap-star-rating
但是,一旦用户选择评级,我就很难访问数据库的值。我目前的代码如下:
<div class="form-group">
@Html.LabelFor(model => model.Rating, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<span class="star">
<input id="input-id" type="radio" value="alert($('input#input-id').val())" class="rating" data-size="lg">
</span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet">
<link href="~/Content/star-rating.css" media="all" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script src="~/Scripts/star-rating.js" type="text/javascript"></script>
<link href="~/Content/theme-krajee-svg.css" media="all" rel="stylesheet" type="text/css" />
<script src="~/Scripts/theme-krajee-svg.js"></script>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
当我在加载页面后检查 HTML 时,我可以看到插件发生了变化:
<input id="input-id" type="radio" value="alert($('input#input-id').val())" class="rating" data-size="lg">
收件人:
<input id="input-id" type="radio" value=//whatever user rates class="rating hide" data-size="lg">
看来我可能正在返回某种类型的隐藏输入?我阅读了此链接,但没有任何效果:
jQuery access input hidden value
我一定是做错了什么。这位新手将不胜感激任何帮助!
【问题讨论】:
-
value=//whatever user rates- 字面意思? -
没有。很抱歉不清楚。该值将是用户点击的任何星星。
标签: javascript jquery html