【问题标题】:Placeholder not working in IE8 & IE9, even using a jQuery plugin占位符在 IE8 和 IE9 中不起作用,即使使用 jQuery 插件
【发布时间】:2014-09-25 01:26:54
【问题描述】:

我正在使用以下插件在 IE8 和 IE9 中显示占位符。我认为它在去年奏效了,而现在却没有:

https://github.com/mathiasbynens/jquery-placeholder

实际上,这个插件在演示页面上完美运行:http://mathiasbynens.be/demo/placeholder

我真的不知道如何解决它。我在 WordPress 中使用它,我在其中加载本地 jQuery,如果我记得很清楚,这通常是最后一个版本。我在functions.php上将脚本排入队列:

function szt_load_scripts() {

wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_style( 'shortcodes', get_stylesheet_directory_uri() . '/shortcodes.css' );

wp_enqueue_script('jquery');

if ( is_singular() ) { 
    wp_enqueue_script( 'comment-reply' ); 
}

if (ot_get_option('szt_enable_linkbuilding') === "on") {
    wp_deregister_script( 'link-building-pro-min' );
    wp_register_script( 'link-building-pro-min', get_template_directory_uri().'/jquery/link-building-pro/link-building-pro-min.js', array(), true, true);
    wp_enqueue_script( 'link-building-pro-min' );
}

wp_enqueue_script('scripts', get_stylesheet_directory_uri() . '/jquery/scripts.js');
wp_localize_script('scripts', 'contactForm', array(
    'youForgot' => __('<span class="errormsg">You forgot to enter your ', 'wptheme'),
    'invalidEmail' => __('<span class="errormsg">You entered an invalid email.</span>', 'wptheme'),
    'messageSent' => __('<p class="thanks"><strong>Thanks!</strong> Your message was successfully sent.</p>', 'wptheme')
));
}

add_action('wp_enqueue_scripts', 'szt_load_scripts');

我是否以错误的方式加载插件? 我需要使用旧版本的 jQuery 吗? 我需要为此添加不同的修复程序吗?

【问题讨论】:

  • 您在错误控制台中看到了什么(如果有的话)?
  • 您可以转到页面并查看源代码以确保脚本甚至已添加到页面中吗?另外仅添加脚本是不够的,您还需要在document.ready 中运行$('input, textarea').placeholder();
  • 我不知道如何使用错误控制台,@TiesonT。
  • @Gerard 按 F12 键。
  • @TiesonT。它有一个错误:“未捕获的 TypeError:无法读取未定义 measureIt.js:120(匿名函数)的属性 'create'”。但它属于不是主题的文件 measureIt.js。

标签: jquery wordpress placeholder


【解决方案1】:

你必须在(document).ready()里面初始化插件。

【讨论】:

  • 啊,我所做的就是在插件后面插入$('input, textarea').placeholder();。我猜是错的。应该是$(document).ready(function() { $('input, textarea').placeholder(); });。我要测试一下。
  • 还是不行。可能我错过了一些东西。无论如何,我认为您的答案是正确的。我将其投票为已接受的答案。谢谢!
  • 无论如何,您的控制台上有一些错误。修复它会对您有所帮助。
  • 我该怎么做?我很擅长复制和粘贴代码,但我真的不知道如何调试 JavaScript。
  • 嗨@Genethic,我在单击搜索按钮时发现了一个错误(它会显示一个弹出窗口):positionPopup();。你发现更多错误了吗?如我所见,控制台仅在需要执行代码时(在 Google Chrome 和 Firefox 上)调试代码。因此,我推断解决方案是逐个测试所有功能。对吗?
猜你喜欢
  • 2013-09-28
  • 2013-07-15
  • 2012-09-17
  • 1970-01-01
  • 2016-02-29
  • 2013-03-16
  • 2012-04-20
  • 1970-01-01
  • 2013-10-23
相关资源
最近更新 更多