博主:html 带参数搜索
Blogger: html search with parameters
我有一个问题,我在 Blogger 中创建了模板,在那里搜索带有标签的文本需要这个 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?category=Printers&q=SearchText
<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=Category:Printers+SearchText
这可以通过添加一些 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
});
});
你可以试试这个:
function onSubmit(obj){
var searchText = document.getElementById("text").value;
var actionUrl = "/search?q=Category:Printers+"+searchText;
console.log(actionUrl);
obj.form.action=actionUrl;
obj.form.submit();
}
<form action='' class='search' method='GET'>
<input name='q' id="text" idplaceholder='Пошук' type='text'/>
<input id='search_button' id="search" name='' title='Search' onclick="onSubmit(this)"; type='button' value=''/>
</form>
我有一个问题,我在 Blogger 中创建了模板,在那里搜索带有标签的文本需要这个 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?category=Printers&q=SearchText
<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=Category:Printers+SearchText
这可以通过添加一些 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
});
});
你可以试试这个:
function onSubmit(obj){
var searchText = document.getElementById("text").value;
var actionUrl = "/search?q=Category:Printers+"+searchText;
console.log(actionUrl);
obj.form.action=actionUrl;
obj.form.submit();
}
<form action='' class='search' method='GET'>
<input name='q' id="text" idplaceholder='Пошук' type='text'/>
<input id='search_button' id="search" name='' title='Search' onclick="onSubmit(this)"; type='button' value=''/>
</form>