0

私はこのようなアンカータグを持っています

<div id="'+itemArr[0]+'">'+itemArr[1]+' 
<a id="'+itemArr[0]+'" href="javascript:void(0)" onclick="javascript:chatWith('+rep+')"  disabled="true">Chat</a> 
 <a  href="javascript:void(0)" onclick="javascript:changeActive('+value+');" disabled="true">Active</a><br> </div>'

特定のアンカー タグを有効または無効にする方法を教えてください。

よろしくお願いします。

4

2 に答える 2

1
$('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>

ワーキングサンプル

于 2012-08-29T06:58:03.910 に答える
0

次のコードを使用できます。

$(this).attr("id");

または、従来のJavaScriptの方法で、

this.getAttribute('id');
于 2012-08-29T06:54:26.610 に答える