0

これが私のコードです:

<div id="reason_bars">Reason <select style="width:200px;" disabled="disabled"><option><option></select>
<div class="edit" style="position:absolute;left:212px;top:50px;">Edit</div></div>

イベントをトリガーしたいのですが、class = "edit"でdivをクリックすると、要素(その兄弟)が有効になります。

私は次のコードを試しました:

$(document).ready(function () {
$("#reason_bars .edit").click(function () {
var parent=$(this).parent();
$(parent+" select").removeAttr("disabled");
});
});

これは機能しません。

代替手段はありますか?

ありがとう!

4

4 に答える 4

1

これを試してください:

$(document).ready(function () {
$(".edit").click(function () {
   $(this).parent().find('select').removeAttr("disabled");
  });
 });

ここ

于 2011-06-28T11:50:25.910 に答える
1

これを次のように書く必要があります$(parent).find('select').removeAttr("disabled")

于 2011-06-28T11:44:50.203 に答える
0

試す

$(document).ready(function () {
     $("#reason_bars .edit").click(function () {
          $(this).siblings('select').removeAttr("disabled");
     )}
});

行の$(parent+" select")親はオブジェクトへの参照であり、文字列ではないため、機能しません。jQuery兄弟セレクターを使用して物事を単純化することもできます。

お役に立てれば!

于 2011-06-28T11:43:49.280 に答える
0

あなたはこのようなことを試すことができます

$(document).ready(function () {
    $("#reason_bars .edit").click(function () {
        $(this).parent().find("select").removeAttr("disabled");
    });
});
于 2011-06-28T11:46:14.487 に答える