0
我试图显示浏览器窗口宽度onResize()。我读了很多关于它的帖子,但它仍然无法正常工作。 JavaScript从不运行(警报从不出现)。onResize()不适用于WordPress 4.7.2
这种使用onResize =“dispScreenWidth()”的方法在Bootstrap站点中工作正常。我知道get_template_directory_uri()路径是正确的。我刚刚安装了jQuery更新程序,但这没有帮助。
functions.php
<?php
function flashdatadesign_twentytwelve_credits() {
echo 'Website by <a href="http://example.com" title="example">';
}
add_action('twentytwelve_credits', 'mysite_twentytwelve_credits');
wp_enqueue_script('bcscript', get_template_directory_uri().'/js/bcscript.js', array ('jquery'), NULL, true);
?>
header.php
<body <?php body_class(); ?> onResize="dispScreenWidth()">
<div id="page" class="hfeed site">
<p id="diag"></p> // --- this is just to display window.innerWidth
<header id="masthead" class="site-header" role="banner">
<hgroup>
...........
</body>
bcscript.js
jQuery(document).ready(function(){
function dispScreenWidth() {
jQuery('#diag').css('display', 'inline');
jQuery('#diag').html('');
jQuery('#diag').append(window.innerWidth + ', ');
alert('display');
}
});
的jQuery(窗口)。在( '调整',()的函数工作非常感谢 – fuey