こんにちは:その後、ID番号
$('div.panel-group').removeAttr('id', '');
しかし、動作しません。この1つは私のために働い生成されたIDの
Thxを
こんにちは:その後、ID番号
$('div.panel-group').removeAttr('id', '');
しかし、動作しません。この1つは私のために働い生成されたIDの
Thxを
のがスタックが、私は要素のIDと警告を表示し、私はのIDを削除するように私は(例えば、IDを見つけ、その後、IDを削除)したくありませんその要素が表示された場合、IDは未定義です。
<div class="panel-group" id="test">
First Div
</div>
<div class="panel-group" id="test2">
Second Div
</div>
スクリプト:
$('div.panel-group').each(function(){
alert($(this).attr('id'));
$(this).removeAttr('id');
alert($(this).attr('id'));
});
またJsfiddleをご確認ください:とにかくhttps://jsfiddle.net/f72q9wao/
、私たちはより良いアイデアを持つことができますので、いくつかのHTMLを共有してみてください。
Thx、しかし動作しません – roshambo
これを試してください。これはあなたが望むものを説明します。 最初のdivをクリックしてみてください。クラス名があなたの名前に等しい場合は、divのIDを削除します。そのid.tryのすべてのスタイルが削除されます。これがあなたに役立つことを願っています。
<!DOCTYPE html>
<html>
<head>
\t <title></title>
\t <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
\t
</head>
<style type="text/css">
div.container div{
\t width: 100px;
\t height: 100px;
\t border:1px solid black;
\t margin:20px;
\t cursor: pointer;
}
.first{
\t background-color: orange;
}
.second{
\t background-color: pink;
}
.third{
\t background-color: purple;
}
#firstid{
\t border:10px solid red;
}
</style>
<body>
\t
<div class="container">
\t <div class="first" id="firstid">class = "first" and <br> id="firstid"</div>
\t <div class="first" id="secondid">class = "first" and <br>id="secondid"</div>
\t <div class="second" id="thirdid">class = "second" and <br>id="thirdid"</div>
\t <div class="third" id="fourthid">class = "third" and <br>id="fourthid"</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function()
{
\t $("div.container div").click(function(){
\t \t var the_class = $(this).attr('class');//get the class name of clicked one
\t \t var the_id = $(this).attr('id');//get the id of the clicked
\t \t alert("The class name :" +the_class + " and the id :"+the_id);
\t \t //then implment your condition
\t \t if (the_class == "first")
\t \t {
\t \t \t $("[class='first']").removeAttr('id');
\t \t }
\t });
\t
});
</script>
</html>
のみ1パラメータを指定してみてください: '.removeAttr( 'ID')' | https://api.jquery.com/removeAttr/ – kosmos
$( 'div.panel-group')。removeAttr( 'id'); '設定しているパラメータが2つある場合 – guradio
残念ながらこれは動作しません。私は正常に$( '#myID123')を行うことができます。removeAttr( 'id');クラス名を検索したい。 – roshambo