我的应用程序要求用户上传一组必需的文档(上传#1,上传#2,上传#3)。上载完成后,将返回需求标识符(req_id)。
该页面显示要求列表,并且当上传特定项目时,当前将该类从“缺失”更改为“完成”。但是,我也想在上传完成后将“删除”图标的可见性从隐藏更改为可见。
HTML:
<ul>
<li class="missing" rel="1">
<span class="link">
<a href="#" target="_blank">Upload #1</a>
</span>
<span class="controls">
<img src="download.png" class="download" <? if ($req_item['class'] == "missing") { echo 'style="visibility: hidden;"'; } ?> >
<img src="trash.png" class="delete" <? if ($req_item['class'] == "missing") { echo 'style="visibility: hidden;"'; } ?> >
</span>
</li>
<li class="missing" rel="2">
<span class="link">
<a href="#" target="_blank">Upload #2</a>
</span>
<span class="controls">
<img src="download.png" class="download" <? if ($req_item['class'] == "missing") { echo 'style="visibility: hidden;"'; } ?> >
<img src="trash.png" class="delete" <? if ($req_item['class'] == "missing") { echo 'style="visibility: hidden;"'; } ?> >
</span>
</li>
<li class="missing" rel="3">
<span class="link">
<a href="#" target="_blank">Upload #3</a>
</span>
<span class="controls">
<img src="download.png" class="download" <? if ($req_item['class'] == "missing") { echo 'style="visibility: hidden;"'; } ?> >
<img src="trash.png" class="delete" <? if ($req_item['class'] == "missing") { echo 'style="visibility: hidden;"'; } ?> >
</span>
</li>
</ul>
使用Javascript:
function stopUpload(success, req_id){
if (success == 1){
$('#upload_result').html('<span class="msg">Success!<\/span>');
$("ul li[rel=" + req_id + "]").removeClass().addClass('complete')
$("ul li[rel=" + req_id + "]").child('.controls').child('.delete').css('visibility','visible')
}
else {
$('#upload_result', window.parent.document).html(
'<span class="emsg">Error!<\/span>');
}
$('#upload_progress').hide();
return true;
}
答案 0 :(得分:4)
要使用jQuery,请替换
$("ul li[rel=" + req_id + "]").removeClass().addClass('complete')
$("ul li[rel=" + req_id + "]").child('.controls').child('.delete').css('visibility','visible')
人:
$("ul li[rel=" + req_id + "]").removeClass().addClass('complete').find('.controls .delete').show();
但是,您应该使用CSS。因此,请保留原始jQuery并将其添加到CSS:
ul li .controls .delete {
display: block;
}
ul li.complete .controls .delete {
display: none;
}
答案 1 :(得分:0)
您想要更改
$("ul li[rel=" + req_id + "]").child('.controls').child('.delete').css('visibility','visible')
到
$("ul li[rel=" + req_id + "] .controls .delete").show()
应该很好地工作。
我倾向于使用展示属性 - display:none;
或display:block;
或display:inline;