如何解决JavaScript无法在带有EF的ASP.NET MVC中运行
我正在尝试使用click方法将按钮与某些Web应用程序连接起来,但是它不起作用。我网站其余部分上的JS正常运行,但这似乎不适合我。
我是ASP.NET的新手,我正在使用教程,因此,如果以某种方式完成任何操作,那是因为这是在教程中完成的方式。这是我正在创建问题的页面的代码,我将实现javascript函数如何计算montantbrut = courn + courm + cours
创建剃刀视图:
<h2>Create</h2>
<div class="form-horizontal">
<h4>Coordonnee</h4>
<hr />
@Html.ValidationSummary(true,"",new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.EnseignantId,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EnseignantId,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EnseignantId,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Nom,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Nom,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Nom,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Specialite,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Specialite,new SelectList(ViewBag.list),"إختر إختصاص ",htmlAttributes:new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Specialite,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Rang,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Rang,"إختر رتبة ",htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Rang,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Courn,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Courn,new { htmlAttributes = new { @class = "form-control" },@id="courn" })
@Html.ValidationMessageFor(model => model.Courn,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tdn,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tdn,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tdn,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tpn,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tpn,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tpn,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Courm,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Courm,@id="courm" })
@Html.ValidationMessageFor(model => model.Courm,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tdm,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tdm,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tdm,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tpm,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tpm,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tpm,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Cours,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Cours,@id="cours"})
@Html.ValidationMessageFor(model => model.Cours,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tds,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tds,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tds,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tps,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tps,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tps,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Montantbrut,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Montantbrut,@id="montanbrut" })
@Html.ValidationMessageFor(model => model.Montantbrut,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tva,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tva,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tva,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Montantnet,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Montantnet,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Montantnet,new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-primary" onClick="savebtn" />
</div>
</div>
</div>
和Javascript代码:
@section scripts {
<script type="text/javascript">
$(document).ready(function(){
$('courn').change(function () {
$('montantbrut').val = $('courn').val + $('courm').val+ $('cours').val;
alert("test de click");
});
});
</script>
解决方法
在这里,您应该将#
与courn
和其他id's
一起用作JavaScript中的选择器。
$('#courn').change(function () {
var calc = $('#courn').val() + $('#courm').val() + $('#cours').val();
$('#montantbrut').val(calc);
alert("test de click");
});
,
您不要在jquery选择器中使用#号,并且jquery找不到元素。 在查询选择器中,您需要将#用作ID和ID。用于类属性。
正确的代码是:
@section scripts {
<script type="text/javascript">
$(document).ready(function(){
$('#courn').change(function () {
$('#montantbrut').val($('#courn').val() + $('#courm').val() + $('#cours').val());
alert("test de click");
});
});
</script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。