mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-21 08:14:36 +00:00
feat: 添加搜索框
This commit is contained in:
parent
512365fd92
commit
5d2a5a82cb
22
css/app.css
22
css/app.css
@ -105,10 +105,28 @@ body {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
input[type=search] {
|
||||
display: block;
|
||||
form.searchBox {
|
||||
width: 180px;
|
||||
border: 1px solid #4682BE;
|
||||
height:20px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
input[type=search] {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 160px;
|
||||
height: 18px;
|
||||
text-align: left;
|
||||
border: none;
|
||||
}
|
||||
|
||||
input.searchButton {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 160px;
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
#content {
|
||||
|
BIN
images/magnifier.jpg
Normal file
BIN
images/magnifier.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 607 B |
19
js/ditto.js
19
js/ditto.js
@ -75,12 +75,26 @@ function init_sidebar_section() {
|
||||
}
|
||||
|
||||
function init_searchbar() {
|
||||
var search = '<input name="search" type="search">';
|
||||
var search = '<form class="searchBox" onSubmit="return searchbar_listener()">' +
|
||||
'<input name="search" type="search">' +
|
||||
'<input type="image" class="searchButton" src="images/magnifier.jpg" alt="Search" />' +
|
||||
// '<a class="searchLink" href="#" target="_blank"><img src="images/magnifier.jpg"></a>' +
|
||||
'</form>';
|
||||
$(ditto.sidebar_id).find('h2').first().before($(search));
|
||||
$('input[name=search]').keydown(searchbar_listener);
|
||||
// $('input.searchButton').click(searchbar_listener);
|
||||
// $('input[name=search]').keydown(searchbar_listener);
|
||||
}
|
||||
|
||||
function searchbar_listener(event) {
|
||||
// event.preventDefault();
|
||||
var q = $('input[name=search]').val();
|
||||
if (q !== '') {
|
||||
var url = 'https://github.com/ruanyf/es6tutorial/search?utf8=✓&q=' + encodeURIComponent(q);
|
||||
window.open(url, '_blank');
|
||||
win.focus();
|
||||
}
|
||||
return false;
|
||||
/*
|
||||
if (event.which === 13) {
|
||||
var q = $('input[name=search]').val();
|
||||
if (q !== '') {
|
||||
@ -88,6 +102,7 @@ function searchbar_listener(event) {
|
||||
location.href = url;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user