我有这个代码,但它有点重复,有没有办法让它更短?
jQuery(document).ready(function() {
var allTabs = jQuery('#front, #blog, #portfolio, #pages, #colors, #fonts');
allTabs.hide();
jQuery('#front-show').click(function() {
event.preventDefault();
allTabs.hide();
jQuery('#front').show();
});
jQuery('#blog-show').click(function() {
event.preventDefault();
allTabs.hide();
jQuery('#blog').show();
});
jQuery('#portfolio-show').click(function() {
event.preventDefault();
allTabs.hide();
jQuery('#portfolio').show();
});
jQuery('#pages-show').click(function() {
event.preventDefault();
allTabs.hide();
jQuery('#pages').show();
});
jQuery('#colors-show').click(function() {
event.preventDefault();
allTabs.hide();
jQuery('#colors').show();
});
jQuery('#fonts-show').click(function() {
event.preventDefault();
allTabs.hide();
jQuery('#fonts').show();
});
});
Run Code Online (Sandbox Code Playgroud) 我有两个功能:
core_function($atts) {
(attributes)
(core functions, a few loops, echoes, a lot of direct input)
}
Run Code Online (Sandbox Code Playgroud)
这就是我使用输出缓冲显示我的功能的方式(是的,我必须使用它!).
display_function($atts) {
(attributes)
$output = ob_start();
$output .= core_function($atts);
$output .= ob_get_clean();
return $output;
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,但返回$ output不仅显示核心功能,还显示"1".我不知道这个"1"来自哪里.当我删除ob_start(); 和ob_get_clean(); 它消失了.所以我相信输出缓冲区以某种方式添加这个数字.但是怎么样,为什么呢?它是原始的"1",而不是段落等.
Normaly display_function($ atts)显示,例如:
<div>This is Core Function!</div>
Run Code Online (Sandbox Code Playgroud)
通过输出缓冲,它显示:
1 <div>This is Core Function!</div>
Run Code Online (Sandbox Code Playgroud)
为什么会这样?如果它与我的功能有关,我再说一遍 - 1正在显示所有内容之前.
我希望jQuery在我悬停一个元素后做一些事情并在鼠标上执行其他操作.
我写了这个:
jQuery('.item').hover(
function() {
var bg = jQuery(this).attr('data-background');
jQuery(this).css("background-color", bg);
},
function() { /* this doesn't seem to work */
alert(bg);
});
Run Code Online (Sandbox Code Playgroud)
你能告诉我为什么这个代码在第二个函数之前工作正常,所以它从不提醒任何东西?我相信有一个错字,但我找不到; /
我有一个代码:
<?php $loop = some array with posts;
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="class">
<p>(data)</p>
</div>
<?php endwhile; ?>
Run Code Online (Sandbox Code Playgroud)
现在我想要为最后一个循环更改div类(从"class"到"class2").怎么做?
例:
当"一些有帖子的数组"现在有4条记录时,我得到:
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
Run Code Online (Sandbox Code Playgroud)
我想得到:
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class2"><p>data</p></div> <!-- this one is different -->
Run Code Online (Sandbox Code Playgroud)
无论有多少阵列元素,我都在寻找能够工作的东西.
坦克!