0
我正在开发一个c#项目。jQuery有条件地添加/删除onlick和onserverclick属性
我有一个锚标记,我想基于某些条件添加/删除onlick和onserverclick属性。
设计: -
<a class="btnSelected" href="#" name="Platinum" onclick="if (!confirm('Are you sure you want to change the plan?')) return false;" onserverclick="UpdatePackage_Click" runat="server">upgrade</a>
的jQuery: -
if ($("#" + '<%= hdnPackType.ClientID %>').val() != $("#" + '<%= hdnOrigionalPackType.ClientID %>').val()) {
$('a.btnSelected').html('select').attr("onclick", "if (!confirm('Are you sure you want to change the plan?')) return false;");
}
else {
$('a.btnSelected').html('<i class="fa fa-check mr-10"></i>selected').removeAttr('onclick').removeAttr('href');
}
你不能属性添加到文本元素 – madalinivascu
我应该去一个按钮? –
我不知道你在做什么 – madalinivascu