【发布时间】:2014-03-29 15:31:09
【问题描述】:
为什么会出现这个错误:
未捕获的类型错误:无法读取未定义的属性“scrollHeight”。
“阅读更多”按钮将我返回到页面顶部,而不是更改我的 <div> 元素的高度。我该如何解决这个问题?
这是我的代码:
function piki( $atts, $content = null ) {
{ ?>
<script type="text/javascript">
var h = jQuery('#piki')[0].scrollHeight;
jQuery('#more').click(function(e) {
e.stopPropagation();
jQuery('#piki').animate({
'height': h
})
});
jQuery(document).click(function() {
jQuery('#piki').animate({
'height': '50px'
})
})
</script>
<?php }
$url = '/?s=';
$str = '';
$output = array();
$count = 0;
foreach (explode(", ",$content) as $content) {
$count++;
$output[] = "<a href='" . $url . $content . "'>" . $content . "</a>";
if ($count == 50) {
break;
}
}
return '<div id="piki" class="piki">'.implode(", ", $output).'</div><a id="more" style="float: left;" href="#">Read more</a>';
}
add_shortcode( 'piki', 'piki' );
【问题讨论】:
标签: javascript jquery