我正在开发一个c#项目。
我有一个锚标记,我想基于某些条件添加/删除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');
}
答案 0 :(得分:0)
您需要使用数据属性。我为你做了一个例子。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context="net.ossrs.yasea.demo.MainActivity">
<item android:id="@+id/action_settings" android:title="action_settings"
android:orderInCategory="200" app:showAsAction="never" />
<item
android:id="@+id/menu_search"
android:menuCategory="system"
android:title="action_settings"
android:icon="@drawable/logo"
app:showAsAction="always"
/>
<item android:id="@+id/original_filter" android:title="Original" app:showAsAction="never"/>
<item android:id="@+id/beauty_filter" android:title="Beauty" app:showAsAction="never"/>
<item android:id="@+id/cool_filter" android:title="Cool" app:showAsAction="never"/>
<item android:id="@+id/early_bird_filter" android:title="Early Bird" app:showAsAction="never"/>
<item android:id="@+id/evergreen_filter" android:title="Evergreen" app:showAsAction="never"/>
<item android:id="@+id/n1977_filter" android:title="N1977" app:showAsAction="never"/>
<item android:id="@+id/nostalgia_filter" android:title="Nostalgia" app:showAsAction="never"/>
<item android:id="@+id/romance_filter" android:title="Romance" app:showAsAction="never"/>
<item android:id="@+id/sunrise_filter" android:title="Sunrise" app:showAsAction="never"/>
<item android:id="@+id/sunset_filter" android:title="Sunset" app:showAsAction="never"/>
<item android:id="@+id/warm_filter" android:title="Warm" app:showAsAction="never"/>
<item android:id="@+id/tender_filter" android:title="Tender" app:showAsAction="never"/>
<item android:id="@+id/toast_filter" android:title="Toast" app:showAsAction="never"/>
<item android:id="@+id/valencia_filter" android:title="Valencia" app:showAsAction="never"/>
<item android:id="@+id/walden_filter" android:title="Walden" app:showAsAction="never"/>
</menu>
<div class="row text-center">
<div class="col-md-4">
plan 1
<button class="btn btn-info btnSelect" data-plan="1">select</button>
</div>
<div class="col-md-4">
plan 2
<button class="btn btn-info btnSelect" data-plan="2">select</button>
</div>
<div class="col-md-4">
plan 3
<button class="btn btn-info btnSelect" data-plan="3">select</button>
</div>