我试图在使用jquery切换时使用replace命令更改图像..基本显示向下箭头,在内容显示后变成向上箭头。除了向下箭头之外的下面的工作不会被替换。在jquery切换功能上更改图像
<img src="/images/arrow_down.png" id="#1" class="nav-toggle">
<div id="1" style="display:none">some content</div>
,这里是jQuery代码
jQuery('document').ready(function($) {
jQuery('.nav-toggle').click(function() {
var collapse_content_selector = $(this).attr('id');
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function() {
if ($(this).css('display') == 'none') {
} else {
toggle_switch.attr("src").replace("down", "up");
}
});
});
});
的ID不应该以数字开头。 –
为什么你在id中使用#有没有什么理由使用它? –