html - 博主:带参数的html搜索
问题描述
我有一个问题,我在博客中创建模板,并在那里搜索带有标签的文本需要这个 url:
www.my_blog.blogspot.com/search?q=label:Printers+SearchText
我有这个代码:
<form action='/search' class='search' method='GET'>
<input name='q' placeholder='Пошук' type='text'/>
<input id='search_button' name='' title='Search' type='submit' value=''/>
</form>
结果:
www.my_blog.blogspot.com/search?q=SearchText
但我需要使用以下参数进行搜索:
www.my_blog.blogspot.com/search?q=label:Printers+SearchText
我怎么能做到这一点,没有javascript?
解决方案
我建议(如果您不想使用 JS 来处理查询连接)使用隐藏输入创建多个查询属性:
www.my_site.com/search? 类别=打印机& q=搜索文本
<form action='/search' class='search' method='GET'>
<input name='category' value='Printers' type='hidden'>
<input name='q' placeholder='Пошук' type='text'>
<input id='search_button' name='' title='Search' type='submit'>
</form>
嗯,如果你真的,真的需要一个动态连接(前缀)的查询参数值,例如:
www.my_site.com/search? q=类别:打印机+搜索文本
这可以通过添加一些 JS 来实现(为了简单起见,我将使用无所不在的 jQuery 库)
$('form.search').on('submit', function (e) {
// Prevent default form submit
// since we need to cunstruct a prefixed param value
e.preventDefault();
// Set prefix and get SearchText
var pfx = "Category:Printers+";
var val = $(this).find('[name=q]').val();
$.ajax({
url: this.getAttribute("action"),
data: { q : pfx + val } // Join prefix to value into "q" param
}).done(function(res) {
console.log(res); // Success
});
});
推荐阅读
- r - 如何在 purrr 中使用像 reduce2 一样的累积函数?
- python-3.x - CloudWatch 日志流到 Lambda python
- python - 使用 tensorflow seq2seq API 对单个序列进行预测
- react-native - 如何从 react-native-datepicker 获取 unix 时间戳格式的日期?
- c# - 如何从一个列表中的属性中获取随机值?
- java - FileInputStream 找不到文件 intelliJ 思路
- angular5 - 从 Angular 4 更新到 Angular 5 后自定义 FormControl 失败
- laravel - 带有逗号分隔字段的 Laravel Eloquent 关系
- hibernate - spring boot jpa hibernate - 获取主详细数据
- c - 程序没有错误但仍然崩溃