我有一个 php 变量,我将它传递给一个 jquery 脚本,我想设置某个 div 的背景。不过似乎没有任何效果。
这是代码:
<?php $post_thumbnail_id = get_post_thumbnail_id(); ?>
<?php $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id ); ?>
<script type="text/javascript">
$(document).ready(function(){
$("#event-sub-hero").css('background', 'url("<?php echo $post_thumbnail_url ?>")');
});
</script>
<!-- SUBPAGE HEADER -->
<div id="event-sub-hero">
<div class="container">
<div class="sub-hero-text col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-12">
<h2><?php the_title(); ?></h2>
</div> <!-- end sub-hero-text -->
</div> <!-- end container -->
</div> <!-- end sub-hero -->
<!-- END SUBPAGE HEADER -->
这是它吐出的代码:
$(document).ready(function(){
$("#event-sub-hero").css('background', 'url("http://localhost:8888/babble/wp-content/uploads/2013/10/madmen-night.jpg")');
});