$('a').on('click', function() {
var disabled = $(this).attr('disabled');
// checking that disabled exists or not
// as I bind click to all anchor tags
if( typeof attr !== 'undefined' && attr !== false ) {
$(this).attr('disabled', disabled == 'true' ? 'false' : 'true');
}
});
其他方式:
$('a[disabled]').on('click', function() {
this.disabled = this.disabled == 'true' ? 'false' : 'true';
});
根据评论
试试这个:
<a href="javascript:void(0)" onclick="javascript:changeActive(this, 'value');" disabled="true">Active</a>
<script>
function changeActive(el, val) {
var disabled = el.getAttribute('disabled');
if( typeof disabled !== 'undefined' && disabled != null ) {
el.setAttribute('disabled', disabled == 'true' ? 'false' : 'true');
}
}
</script>
工作样本