我想修改我的jquery脚本以添加一个不同的#id [英] I would like to amend my jquery script to add a different #id
本文介绍了我想修改我的jquery脚本以添加一个不同的#id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个jquery代码,可在点击时将内容压低:
I have this jquery code which pushes the content down on click:
<script>
$(document).ready(function() {
$('#showhide').click(function() {
if($('#author-dropdown').css('display') == 'none') {
$('#author-dropdown').slideDown();
} else {
$('#author-dropdown').slideUp();
}
return false;
});
});
</script>
我想添加一个不同的ID.因此,可以说当脚本不显示时,用户应该看到#author-dropdown,而当display == block时,id应该是#author-dropdown-extended.我应该如何修改此脚本以使其实现?
I would like to add up a different id. So, lets say when the script is to display==none, user should see #author-dropdown and when display==block, the id should be #author-dropdown-extended. How should I amend this script to make it happen?
推荐答案
$('#author-dropdown').attr("id","author-dropdown-extended").slideDown();
,并更改以下内容以将其设置回原始状态
and also change the following to set it back to original state
$('#author-dropdown-extended').attr("id","author-dropdown").slideUp();
尽管如此,我还是会亲自尝试一下……
I would personally try something like this though...
$('#showhide').click(function() {
if($('.author-dropdown').is(':hidden')) {
$('.author-dropdown').slideDown().removeClass('author-dropdown').addClass('author-dropdown-extended');
} else {
$('.author-dropdown').slideUp().removeClass('author-dropdown-extended').addClass('author-dropdown');
}
return false;
});
这篇关于我想修改我的jquery脚本以添加一个不同的#id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文