【发布时间】:2016-04-18 04:22:27
【问题描述】:
我正在使用 WooCommerce 产品搜索小部件并在此代码中添加 minlength="17" 片段:
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products…', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" minlength="17" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />
<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
<input type="hidden" name="post_type" value="product" />
</form>
它在 Chrome 中运行得非常好。它显示一条消息:
"请将此文本延长至 17 个字符或更多(您目前 使用 * 字符)"。
这是我需要的,但在 Firefox 和 IE 中不需要。 当我在搜索字段中输入 3,4 或少于 17 个字符时,它会开始搜索。
怎么办?如何让它在所有浏览器中运行?!
【问题讨论】:
-
试试这样的,
<input pattern=".{17,}" required title="17 characters minimum"> -
目前并非所有浏览器都支持minlength ..wufoo.com/html5/attributes/…
-
我不确定我是否理解如何在我的代码中实现 。无论如何,它不会在我认为的所有浏览器中工作。
-
pattern=".{17,}" required title="17 characters minimum"这就是你需要的。 -
我在上面的代码中究竟可以在哪里添加这个片段??
标签: php html wordpress woocommerce woothemes