想知道是否有人能建议为什么这不起作用,请。
当用户进入搜索表单的空间时,它被#取代,所以如果在搜索栏中输入“红色引导大小9”,它将被替换为(#不被发送到数据库,只是为了显示) #Red#boots#size#9。
$("#s").keyup(function () {
var textValue = $(this).val();
textValue =textValue.replace(/ /g,"#");
$(this).val(textValue);
}); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form role="search" method="get" id="searchform" class="searchform" action="http://tag2.testsiteonline.co.uk/">
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
头码
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- Magnific Popup core CSS file -->
<link rel="stylesheet" href="magnific-popup/magnific-popup.css">
<link rel="stylesheet" href="/fonts/styles.css">
<!-- jQuery 1.7.2+ or Zepto.js 1.0+ -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://tag2.testsiteonline.co.uk/searchjs.js"></script>
<!-- Magnific Popup core JS file -->
<script src="magnific-popup/jquery.magnific-popup.js"></script>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php wp_head(); ?>
</head>也是在我的searchjs.js上--这就是我所有的东西吗?我应该在这之前还是之后吃点什么?
$("#s").keyup(function () {
var textValue = $(this).val();
textValue =textValue.replace(/ /g,"#");
$(this).val(textValue);
});发布于 2017-11-02 20:36:51
您的代码运行良好,下面是一个用来证明的操作:http://jsfiddle.net/zez7w74d/
在加载js文件的地方发布您的<head>内容,以检查是否有可能中断。
编辑:从wordpress中删除所有手动加载的jQuery,因为wordpress附带了根据开发页面jQuery:https://premium.wpmudev.org/blog/adding-jquery-scripts-wordpress/
然后像这样调用您的jQuery代码:
jQuery("#s").keyup(function () {
var textValue = $(this).val();
textValue =textValue.replace(/ /g,"#");
$(this).val(textValue);
});https://stackoverflow.com/questions/47083491
复制相似问题