$('.clsComp').change(function () {
var a = $(this);
var b = $(this).val();
$('.clsComp').not(this).each(function () {
if ($(this).val() === b)
{
a.val('-1'); //default value in my datatable
alert('Already Exists');
return false;
}
});
});
related GridView列
<asp:TemplateField HeaderText="Component">
<ItemTemplate>
<asp:DropDownList ID="ddlComponent" ClientIDMode="Predictable" runat="server" CssClass="clsComp js-example-placeholder-single" Width="100%"></asp:DropDownList>
<asp:CompareValidator ID="CompareValidator10" ClientIDMode="Predictable" runat="server" ControlToValidate="ddlComponent" CssClass="error" Display="Dynamic" ErrorMessage="Select" Operator="NotEqual" ValidationGroup="save" ValueToCompare="-1" ForeColor="Red"></asp:CompareValidator>
</ItemTemplate>
<HeaderStyle ForeColor="White" BackColor="#337ab7" Width="14%" HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
当一个现有的项目被选中时,它会发出警报。但是相关的选项(given in a.val('-1')
)没有被选中(对于任何值,不仅仅是-1)。感谢你的帮助。谢谢!
发布于 2016-05-24 20:27:05
通过这个更改你的脚本
$('.clsComp').change(function () {
var a = $(this);
var b = $(this).val();
$('.clsComp').not(this).each(function () {
if ($(this).val() === b)
{
$(this).prop('selected', true);
alert('Already Exists');
return false;
}
});
});
https://stackoverflow.com/questions/37413124
复制相似问题