导航栏搜索支持enter键

This commit is contained in:
sw 2015-08-29 11:28:02 +08:00
parent 7263598851
commit e5bf355a17
2 changed files with 22 additions and 4 deletions

View File

@ -19,7 +19,7 @@
</div>
<script>
<% type = type%>
$(document).ready(function (){
$(function (){
if('<%= type %>' != null && '<%= type %>' == 'courses' ){
$('input:radio[value="courses"]').attr('checked','checked');
}
@ -30,13 +30,22 @@
$('input:radio[value="users"]').attr('checked','checked');
}
});
$(function(){
$("#navHomepageSearchInput").keypress(function(e){
if (e.keyCode == '13') {
$('#type').val($('input[type=radio]:checked').val());
$(this).parent().submit();
}
})
});
</script>
<div class="fl" id="navHomepageSearch">
<!--<form class="navHomepageSearchBox">-->
<% name = name%>
<%= form_tag({controller: :welcome, action: :search },:class=>'navHomepageSearchBox', method: :get) do %>
<input type="text" name="q" value="<%= name.nil? ? "" : name%>" class="navHomepageSearchInput" placeholder="请输入关键词进行搜索" />
<input type="text" name="q" value="<%= name.nil? ? "" : name%>" id="navHomepageSearchInput" class="navHomepageSearchInput" placeholder="请输入关键词进行搜索"/>
<input type="hidden" name="search_type" id="type" value=""/>
<a href="javascript:void(0);" class="homepageSearchIcon" onclick="$('#type').val($('input[type=radio]:checked').val());$(this).parent().submit();"></a>
<% end %>

View File

@ -19,7 +19,7 @@
$(doc).parent().submit();
}
<% type = type%>
$(document).ready(function (){
$(function (){
if('<%= type %>' != null && '<%= type %>' == 'courses' ){
$('input:radio[value="courses"]').attr('checked','checked');
}
@ -30,13 +30,22 @@
$('input:radio[value="users"]').attr('checked','checked');
}
});
$(function(){
$("#navHomepageSearchInput").keypress(function(e){
if (e.keyCode == '13') {
$('#type').val($('input[type=radio]:checked').val());
$(this).parent().submit();
}
})
});
</script>
<div class="fl" id="navHomepageSearch">
<!--<form class="navHomepageSearchBox">-->
<% name = name%>
<%= form_tag({controller: :welcome, action: :search },:class=>'navHomepageSearchBox', method: :get) do %>
<input type="text" name="q" value="<%= name.nil? ? "" : name%>" class="navHomepageSearchInput" placeholder="请输入关键词进行搜索" />
<input type="text" name="q" value="<%= name.nil? ? "" : name%>" id="navHomepageSearchInput" class="navHomepageSearchInput" placeholder="请输入关键词进行搜索" />
<input type="hidden" name="search_type" id="type" value=""/>
<a href="javascript:void(0);" class="homepageSearchIcon" onclick="$('#type').val($('input[type=radio]:checked').val());$(this).parent().submit();"></a>
<% end %>