我对TextBox
有疑问。当我输入重复数据时,它不允许。这正是我需要的,但在再次保存数据后,它允许重复数据。我该如何处理这个场景?
这是我的代码。
var Controls = {
saveObjectives: function (actionurl) {
var frm = $('form[name=frmObjectives]')
frm.attr('action', actionurl);
frm.submit();
},
addObjectiveCheckbox: function () {
var text = $('#txtObjective').val();
$('#txtObjective').val('');
if ($.trim(text) == '')
return;
if ($('input[type=checkbox][value="' + text + '"]').length == 0)
$('#dvObjectives').prepend('<input type="checkbox" name="chkNewobjectives" value="' + text + '" Checked /> ' + text + '<br />');
},
我的HTML代码是:
<input id="btnAddObj" class="btn" type="button" onclick="Controls.addObjectiveCheckbox();" value="Add Objective"/>
</div>
<div id="dvObjectives" name="ObjectivesList">
@foreach (Andromeda.Core.Entities.Objectives objective in Model)
{
<label class="checkbox">
<input type="checkbox" name="chkobjectives" Checked value="@objective.ObjectiveID" />@objective.ObjectiveText
</label>
}
</div>
答案 0 :(得分:1)
你在jQuery中使用value ='what text`,但在视图中使用value ='ObjectiveID'。这应该解决它:
<input type="checkbox" name="chkobjectives" Checked value="@objective.ObjectiveText" />@objective.ObjectiveText