0
我如何获取URL链接以在搜索框外显示?通常情况下,搜索框会显示结果并打开一个新页面,其中包含与该搜索结果关联的链接。如何在搜索框外显示网址? (PHP,JS和HTML)
我不希望它在点击搜索结果时打开另一个页面,只是在搜索框下面(不在搜索结果中)显示完整的URL(https://www.php.net.。)。我不想看到目标网页的内容,只能看到搜索框下方空白处的网址。 (示例中显示图像中的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);
/* \t var query_value = $('input#search').val();
\t \t $('b#search-string').text(query_value);
\t \t if(query_value !== ''){
\t \t \t $.ajax({
\t \t \t \t type: "POST",
\t \t \t \t url: "search.php",
\t \t \t \t data: { query: query_value },
\t \t \t \t cache: false,
\t \t \t \t success: function(html){
\t \t \t \t \t $("ul#results").html(html);
\t \t \t \t } \t
\t \t \t }); \t */
}
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 {
\t margin: 0;
\t padding: 0;
\t border: 0;
\t font-size: 100%;
\t font: inherit;
\t vertical-align: baseline;
\t font-weight: normal;
\t -webkit-font-smoothing: antialiased;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
\t display: block;
}
body {
\t line-height: 1;
}
ol, ul {
\t list-style: none;
}
blockquote, q {
\t quotes: none;
}
blockquote:before, blockquote:after, q:before, q:after {
\t content: '';
\t content: none;
}
table {
\t border-collapse: collapse;
\t border-spacing: 0;
}
a {
\t outline: none;
\t text-decoration: none;
}
/******************************************************************
Print Styles
******************************************************************/
@media print {
* {
\t background: transparent !important;
\t color: black !important;
\t text-shadow: none !important;
\t filter:none !important;
\t -ms-filter: none !important;
}
a, a:visited {
\t text-decoration: underline;
}
a[href]:after {
\t content: " (" attr(href) ")";
}
abbr[title]:after {
\t content: " (" attr(title) ")";
}
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after {
content: "";
}
pre, blockquote {
\t border: 1px solid #999;
\t page-break-inside: avoid;
}
thead {
\t display: table-header-group;
}
tr, img {
\t page-break-inside: avoid;
}
img {
\t max-width: 100% !important;
}
@page {
margin: 0.5cm;
}
p, h2, h3 {
\t orphans: 3;
\t widows: 3;
}
h2, h3 {
\t page-break-after: avoid;
}
}
/******************************************************************
Text Selection Styles
******************************************************************/
/* Safari, Chrome, iPhones, iPads */
::selection {
\t background:#4096ee;
\t color:#fff;
}
::-moz-selection {
\t background:#4096ee;
\t color:#fff;
}
::-webkit-selection {
\t background:#4096ee;
\t color:#fff;
}
/******************************************************************
General CSS
******************************************************************/
p {
\t font-family: Verdana, Arial, sans-serif;
\t line-height: 1.6em;
\t color: #616161;
\t font-size: 10px;
}
h1 {
\t font-family: 'PT Sans', Verdana, Arial, sans-serif;
\t font-weight: bold;
\t line-height: 1.6em;
\t color: #616161;
\t text-decoration: none;
\t font-size: 20px;
}
h2 {
\t font-family: 'PT Sans', Verdana, Arial, sans-serif;
\t line-height: 1.6em;
\t color: #616161;
\t text-decoration: none;
\t font-size: 16px
}
h3 {
\t font-family: 'PT Sans', Verdana, Arial, sans-serif;
\t line-height: 1.6em;
\t color: #616161;
\t text-decoration: none;
\t font-size: 14px;
}
h4 {
\t font-family: 'PT Sans', Verdana, Arial, sans-serif;
\t line-height: 1.6em;
\t color: #616161;
\t text-decoration: none;
\t font-size: 12px;
}
h5 {
\t font-family: 'PT Sans', Verdana, Arial, sans-serif;
\t line-height: 1.6em;
\t color: #ababab;
\t text-decoration: none;
\t font-size: 10px;
}
h6 {
\t font-family: 'PT Sans', Verdana, Arial, sans-serif;
\t line-height: 1.6em;
\t color: #ababab;
\t text-decoration: none;
\t font-size: 8px;
}
/******************************************************************
Main CSS
******************************************************************/
div#main {
\t width: 360px;
\t margin: 200px auto 20px auto;
}
.title {
\t line-height: 1.2em;
\t position: relative;
\t margin-left: 40px;
}
div.icon {
\t margin-top: 4px;
\t float: left;
\t width: 31px;
\t height: 30px;
\t background-image: url(../images/magnify.gif);
\t background-repeat: no-repeat;
\t -webkit-transition-property: background-position, color;
\t -webkit-transition-duration: .2s, .1s;
\t -webkit-transition-timing-function: linear, linear;
\t -moz-transition-property: background-position, color;
\t -moz-transition-duration: .2s, .1s;
\t -ms-transition-duration: .2s, .1s;
\t -ms-transition-timing-property: linear, linear;
\t -o-transition-property: background-position, color;
\t -o-transition-duration: .2s, .1s;
\t -o-transition-timing-property: linear, linear;
\t transition-property: background-position, color;
\t transition-duration: .2s, .1s;
\t transition-timing-property: linear, linear;
}
div.icon:hover {
\t background-position: 0px -30px;
\t cursor: pointer;
}
input#search {
\t width: 350px;
\t height: 25px;
\t padding: 5px;
\t margin-top: 15px;
\t margin-bottom: 15px;
\t -webkit-border-radius: 2px;
\t -moz-border-radius: 2px;
\t border-radius: 2px;
\t outline: none;
\t border: 1px solid #ababab;
\t font-size: 20px;
\t line-height: 25px;
\t color: #ababab;
}
input#search:hover, input#search:focus {
\t color: #3b3b3b;
\t border: 1px solid #36a2d2;
\t -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
\t -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
\t box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
}
h4#results-text {
\t /*display: none;*/
\t font-family: 'PT Sans', Verdana, Arial, sans-serif;
\t line-height: 1.6em;
\t color: #000fff;
\t text-decoration: none;
\t font-size: 16px;
}
ul#results {
\t display: none;
\t width: 360px;
\t margin-top: 4px;
\t border: none;
\t -webkit-border-radius: 0px;
\t -moz-border-radius: 0px;
\t /*border-radius: 0px;
\t -webkit-box-shadow: rgba(0, 0, 0, .15) 0 1px 3px;
\t -moz-box-shadow: rgba(0,0,0,.15) 0 1px 3px;
\t box-shadow: rgba(0, 0, 0, .15) 0 1px 3px;*/
}
ul#results li {
\t padding: 8px;
\t cursor: pointer;
\t border-top: 1px solid #cdcdcd;
\t transition: background-color .3s ease-in-out;
\t -moz-transition: background-color .3s ease-in-out;
\t -webkit-transition: background-color .3s ease-in-out;
}
ul#results li:hover {
\t background-color: #F7F7F7;
}
ul#results li:first-child {
\t border-top: none;
}
ul#results li h3, ul#results li h4 {
\t transition: color .3s ease-in-out;
\t -moz-transition: color .3s ease-in-out;
\t -webkit-transition: color .3s ease-in-out;
\t color: #616161;
\t line-height: 1.2em;
}
ul#results li:hover h3, ul#results li:hover h4 {
\t color: #3b3b3b;
\t 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>
你的意思是删除$ html。=''; ? –
不行,在这行'$ html。='';'只是删除这个'target =“_ blank”“' –