如何制作此$(".spinner #6").hide();
?有没有办法让它成为那样?因为如果我使用这个$(".spinner").attr("id", yes).show();
或$(".spinner").attr("id", 6).show();
..那么所有id ="" , 会出现。如果我使用这段代码$(".spinner").find("id", yes).css("display", "block");
什么也没发生。有没有办法应对这种事情?
<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>
答案 0 :(得分:0)
答案 1 :(得分:0)
id始终是唯一的。你可以使用类本身隐藏和显示。更改下面给出的代码。用于选择div类并隐藏另一个类中的span类。你可以使用$(“。icon-groupx&gt; .ss-icon.spinner”)。show();例子
<div class="outer">
<div class="inner"></div>
</div>
你应该像这样使用
$('.outer > .inner')
如果一个类包含空格
ex:<class="text one" > then $(".text.one").show(); is the way to use
您的代码更改如下所示并尝试
<div class="icon-groupx" id="6">
<span class="ss-icon spinner" id="7" style="display:none;"></span>
<span class="ss-icon ss-heart-no" id="8" style="display:none;"></span>
<span class="ss-icon ss-heart-yes" id="9"></span>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".ss-heart-yes").click(function() {
var idclass=$(this).attr("id");
var dataString = 'idclass='+ idclass;
$(".icon-groupx > .ss-icon.spinner").show();
$(".icon-groupx > .ss-icon.ss-heart-yes").hide();
$.ajax({
type: "POST",
url: "processed.php",
data: dataString,
cache: false,
success: function(result){
var result=trim(result);
if(result=='OK'){
$(".icon-groupx > .ss-icon.ss-heart-no").show();
$(".icon-groupx > .ss-icon.ss-heart-yes").hide();
$(".icon-groupx > .ss-icon.spinner")hide();
} else {
echo "error";
}
}
});
});
});
</script>
答案 2 :(得分:0)
你可以试试这个
<div class="icon-groupx" id="6">
<span class="ss-icon spinner" id="spinner6" src="6" style"display:none;"></span>
<span class="ss-icon ss-heart-no" id="heartno6" src="6" style"display:none;"></span>
<span class="ss-icon ss-heart-yes" id="heartyes6" src="6" ></span>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".ss-heart-yes").click(function() {
var ID=$(this).attr("src");
var dataString = 'idclass='+ idclass;
$("#spinner"+ID).show();
$("#heartyes"+ID).hide();
$.ajax({
type: "POST",
url: "processed.php",
data: dataString,
cache: false,
success: function(result){
var result=trim(result);
if(result=='OK'){
$("#heartno"+ID).show();
$("#heartyes"+ID).hide();
$("#spinner"+ID)hide();;
} else {
echo "error";
}
}
});
});
});
</script>