【发布时间】:2010-10-26 00:46:38
【问题描述】:
我已在未使用任何 CMS 的演示页面上测试了以下脚本。 该脚本位于 index.php 文件中,运行良好。
<form method="get" action="">
<input id="label_search" type="text" value="" maxlength="40" name="inputText"/>
</form>
<script type="text/javascript">
var options = {
script:"includes/autosuggest.php?json=true&",
varname:"input",
minchars: 2,
delay: 200,
json:true,
shownoresults:false,
maxresults:15,
timeout: 5000
};
var as_json = new bsn.AutoSuggest('inputText', options);
</script>
现在我想在 Wordpress 模板文件中使用相同的代码。 但什么都没有发生。似乎脚本根本没有触发。
我正在使用用户友好的 URL,并将自定义永久链接设置为 /%category%/%postname%。 或许有话要说?
我知道 bsn.AutoSuggest_2.1.3.js 正在运行,因为在页面加载时对文件执行“alert('hello')”测试。
可能出了什么问题?
这是我的 WP 代码:
sl_startpage.php:
<?php
/*
Template Name: SL - Start page
*/
get_header(); ?>
<div id="myArea">
<?php
include_once('includes/storeLocator/sl_header.php');
?>
</div>
<?php
get_footer();
?>
这是 sl_header.php 中的(简化的)代码:
<div id="sl-header">
<form method="get" action="">
<input id="label_search" type="text" value="" maxlength="40" name="product_search"/>
</form>
</div>
<script type="text/javascript">
var options = {
script:"includes/autosuggest.php?json=true&",
varname:"input",
minchars: 2,
delay: 200,
json:true,
shownoresults:false,
maxresults:15,
timeout: 5000
};
var as_json = new bsn.AutoSuggest('product_search', options);
</script>
大家有什么建议吗?
这是我使用的插件: http://www.brandspankingnew.net/archive/2007/02/ajax_auto_suggest_v2.html
【问题讨论】:
标签: jquery wordpress autocomplete