如何在搜索框外显示网址链接?通常,搜索框会显示结果并打开一个新页面,其中包含与该搜索结果相关联的链接。
单击搜索结果时,我不希望它打开另一个页面,只需在搜索框下方显示完整的URL(https://www.php.net.。)(不在搜索结果中)。我不希望看到目标页面的内容,只看到搜索框下方空格中的URL。 (示出图像中的部分B的示例)
我认为我已经正确修改了JS。
(由于PHP在代码片段上不起作用,我有附加php文件的下载链接。困在php文件的第48行) https://www.dropbox.com/s/kkg1s4riwjyhzne/search.php?dl=0
$(document).ready(function() {
// Icon Click Focus
$('div.icon').click(function() {
$('input#search').focus();
});
// Live Search
// On Search Submit and Get Results
function search() {
var query_value = $('input#search').val();
$('b#search-string').text(query_value);
if (query_value !== '') {
$("#search-url").attr("href", "search.php?query=" + query_value);
/* var query_value = $('input#search').val();
$('b#search-string').text(query_value);
if(query_value !== ''){
$.ajax({
type: "POST",
url: "search.php",
data: { query: query_value },
cache: false,
success: function(html){
$("ul#results").html(html);
}
}); */
}
return false;
}
$("input#search").live("keyup", function(e) {
// Set Timeout
clearTimeout($.data(this, 'timer'));
// Set Search String
var search_string = $(this).val();
// Do Search
if (search_string == '') {
$("ul#results").fadeOut();
$('h4#results-text').fadeOut();
} else {
$("ul#results").fadeIn();
$('h4#results-text').fadeIn();
$(this).data('timer', setTimeout(search, 100));
};
});
});
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after, q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a {
outline: none;
text-decoration: none;
}
/******************************************************************
Print Styles
******************************************************************/
@media print {
* {
background: transparent !important;
color: black !important;
text-shadow: none !important;
filter:none !important;
-ms-filter: none !important;
}
a, a:visited {
text-decoration: underline;
}
a[href]:after {
content: " (" attr(href) ")";
}
abbr[title]:after {
content: " (" attr(title) ")";
}
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after {
content: "";
}
pre, blockquote {
border: 1px solid #999;
page-break-inside: avoid;
}
thead {
display: table-header-group;
}
tr, img {
page-break-inside: avoid;
}
img {
max-width: 100% !important;
}
@page {
margin: 0.5cm;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3 {
page-break-after: avoid;
}
}
/******************************************************************
Text Selection Styles
******************************************************************/
/* Safari, Chrome, iPhones, iPads */
::selection {
background:#4096ee;
color:#fff;
}
::-moz-selection {
background:#4096ee;
color:#fff;
}
::-webkit-selection {
background:#4096ee;
color:#fff;
}
/******************************************************************
General CSS
******************************************************************/
p {
font-family: Verdana, Arial, sans-serif;
line-height: 1.6em;
color: #616161;
font-size: 10px;
}
h1 {
font-family: 'PT Sans', Verdana, Arial, sans-serif;
font-weight: bold;
line-height: 1.6em;
color: #616161;
text-decoration: none;
font-size: 20px;
}
h2 {
font-family: 'PT Sans', Verdana, Arial, sans-serif;
line-height: 1.6em;
color: #616161;
text-decoration: none;
font-size: 16px
}
h3 {
font-family: 'PT Sans', Verdana, Arial, sans-serif;
line-height: 1.6em;
color: #616161;
text-decoration: none;
font-size: 14px;
}
h4 {
font-family: 'PT Sans', Verdana, Arial, sans-serif;
line-height: 1.6em;
color: #616161;
text-decoration: none;
font-size: 12px;
}
h5 {
font-family: 'PT Sans', Verdana, Arial, sans-serif;
line-height: 1.6em;
color: #ababab;
text-decoration: none;
font-size: 10px;
}
h6 {
font-family: 'PT Sans', Verdana, Arial, sans-serif;
line-height: 1.6em;
color: #ababab;
text-decoration: none;
font-size: 8px;
}
/******************************************************************
Main CSS
******************************************************************/
div#main {
width: 360px;
margin: 200px auto 20px auto;
}
.title {
line-height: 1.2em;
position: relative;
margin-left: 40px;
}
div.icon {
margin-top: 4px;
float: left;
width: 31px;
height: 30px;
background-image: url(../images/magnify.gif);
background-repeat: no-repeat;
-webkit-transition-property: background-position, color;
-webkit-transition-duration: .2s, .1s;
-webkit-transition-timing-function: linear, linear;
-moz-transition-property: background-position, color;
-moz-transition-duration: .2s, .1s;
-ms-transition-duration: .2s, .1s;
-ms-transition-timing-property: linear, linear;
-o-transition-property: background-position, color;
-o-transition-duration: .2s, .1s;
-o-transition-timing-property: linear, linear;
transition-property: background-position, color;
transition-duration: .2s, .1s;
transition-timing-property: linear, linear;
}
div.icon:hover {
background-position: 0px -30px;
cursor: pointer;
}
input#search {
width: 350px;
height: 25px;
padding: 5px;
margin-top: 15px;
margin-bottom: 15px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
outline: none;
border: 1px solid #ababab;
font-size: 20px;
line-height: 25px;
color: #ababab;
}
input#search:hover, input#search:focus {
color: #3b3b3b;
border: 1px solid #36a2d2;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
}
h4#results-text {
/*display: none;*/
font-family: 'PT Sans', Verdana, Arial, sans-serif;
line-height: 1.6em;
color: #000fff;
text-decoration: none;
font-size: 16px;
}
ul#results {
display: none;
width: 360px;
margin-top: 4px;
border: none;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
/*border-radius: 0px;
-webkit-box-shadow: rgba(0, 0, 0, .15) 0 1px 3px;
-moz-box-shadow: rgba(0,0,0,.15) 0 1px 3px;
box-shadow: rgba(0, 0, 0, .15) 0 1px 3px;*/
}
ul#results li {
padding: 8px;
cursor: pointer;
border-top: 1px solid #cdcdcd;
transition: background-color .3s ease-in-out;
-moz-transition: background-color .3s ease-in-out;
-webkit-transition: background-color .3s ease-in-out;
}
ul#results li:hover {
background-color: #F7F7F7;
}
ul#results li:first-child {
border-top: none;
}
ul#results li h3, ul#results li h4 {
transition: color .3s ease-in-out;
-moz-transition: color .3s ease-in-out;
-webkit-transition: color .3s ease-in-out;
color: #616161;
line-height: 1.2em;
}
ul#results li:hover h3, ul#results li:hover h4 {
color: #3b3b3b;
font-weight: bold;
}
<!DOCTYPE HTML>
<html>
<head>
<!-- Meta -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Live Search Tutorial</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- Load CSS -->
<link href="style/style.css" rel="stylesheet" type="text/css" />
<!-- Load Fonts -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:regular,bold" type="text/css" />
<!-- Load jQuery library -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- Load custom js -->
<!--<script type="text/javascript" src="custom.js"></script>-->
</head>
<body>
<div id="main">
<!-- Main Title -->
<div class="icon"></div>
<h1 class="title">Live Search Tutorial</h1>
<h5 class="title">(searches through php functions and shows them on php.net)</h5>
<!-- Main Input -->
<input type="text" id="search" autocomplete="off">
<!-- Show Results -->
<!--<h4 id="results-text">Showing results for: <b id="search-string">Array</b> -->
<a id="search-url" href="">View search results in another tab or window</a>
</h4>
<ul id="results"></ul>
</div>
</body>
</html>
答案 0 :(得分:0)
据我了解你有两个问题
所以我的解决方案
对于第一个问题,只需转到您的search.php文件并删除目标属性
// Define Output HTML Formating
$html = '';
$html .= '<li class="result">';
$html .= '<a href="urlString">'; // remove target attribute from here
$html .= '<h3>nameString</h3>';
$html .= '<h4>functionString</h4>';
$html .= '</a>';
$html .= '</li>';
对于第二个问题,你可以在设计上创建并将结果输入其中
如果不需要ul以便你可以自定义它,你还需要在serach.php中更改结果模板