我該如何製作這個$(".spinner #6").hide();
?有沒有辦法做到這一點?因爲如果我使用像這樣$(".spinner").attr("id", yes).show();
或$(".spinner").attr("id", 6).show();
..那麼所有id =「」,都會出現。如果我使用這個代碼$(".spinner").find("id", yes).css("display", "block");
什麼都沒有發生。有辦法處理這種事情嗎?如何在class元素中調用id元素?
<div class="icon-groupx" id="6">
<span class="ss-icon spinner" id="6" style"display:none;"></span>
<span class="ss-icon ss-heart-no" id="6" style"display:none;"></span>
<span class="ss-icon ss-heart-yes" id="6"></span>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".ss-heart-yes").click(function() {
var idclass=$(this).attr("id");
var dataString = 'idclass='+ idclass;
$(".spinner #6").show();
$(".ss-heart-yes #6").hide();
$.ajax({
type: "POST",
url: "processed.php",
data: dataString,
cache: false,
success: function(result){
var result=trim(result);
if(result=='OK'){
$(".ss-heart-no #6").show();
$(".ss-heart-yes #6").hide();
$(".spinner #6")hide();
///// OR /////
$(".ss-heart-no #idclass").show();
$(".ss-heart-yes #idclass").hide();
$(".spinner #idclass")hide();
///// OR /////
$(".ss-heart-no idclass").show();
$(".ss-heart-yes idclass").hide();
$(".spinner idclass")hide();;
} else {
echo "error";
}
}
});
});
});
</script>
ID應該是唯一的,難怪你有問題。 – rjdown