我对jquery很新,想知道如何结合jquery函数。现在,我的代码有点乱!我已经做了一些研究,并且在组合函数时无法保持正常运行。我不想让我的代码看起来像这样,但至少现在它工作正常(Firefox除外)。结合功能的最佳做法是什么?将多个jquery函数合并为一个函数
<script type="text/javascript">
$(document).ready(function() {
jQuery(function(){
jQuery("#music").click(function() {
jQuery("#musicinfo").slideToggle('slow');
jQuery("#fpinfo, #behindinfo, #behindinfo, #signupinfo").hide('slow');
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
jQuery(function(){
jQuery("#fproduct").click(function() {
jQuery("#fpinfo").slideToggle('slow');
jQuery("#musicinfo, #behindinfo, #behindinfo, #signupinfo").hide('slow');
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
jQuery(function(){
jQuery("#behind").click(function() {
jQuery("#behindinfo").slideToggle('slow');
jQuery("#fpinfo, #musicinfo, #signupinfo").hide('slow');
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
jQuery(function(){
jQuery(".exit").click(function() {
jQuery("#behindinfo, #musicinfo, #fpinfo, #signupinfo").hide('slow');
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
jQuery(function(){
jQuery("#signup").click(function() {
jQuery("#signupinfo").slideToggle('slow');
jQuery("#fpinfo, #musicinfo, #behindinfo").hide('slow');
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
jQuery(function(){
jQuery(".exit").click(function() {
jQuery("#behindinfo, #musicinfo, #fpinfo, #signupinfo").hide('slow');
});
});
});
</script>
<script>
$('#behind, #fproduct, #music, #signup').click(function(){
var divLoc = $('#top').offset();
$('html, body').animate({scrollTop: divLoc.top}, "slow");
});
</script>
这是HTTPS更适合://代码审查.stackexchange.com/我想。 – Andy
它听起来不像你想要的功能。看起来你正在试图结合脚本块。简单的答案是,您可以通过将所有代码复制到一个块就绪功能来完成。至于代码应该如何布局,codereview确实是一个好地方 –