此 HTML 代码用于选择旅行的日期和目的地。我想在自动完成功能之外显示我的结果(目的地)。
如何在框中调用自动完成结果( jquery中的confirm
检查语句)?if else
这是我的代码。
<!DOCTYPE html>
<html>
<head>
<title>Pick a Date</title>
<link rel='stylesheet' type='text/css' href="style/jquery-ui.css"/>
<script src="script/jquery-1.9.1.js"></script>
<script src="script/1.10.3-jquery-ui.js"></script>
<link rel='stylesheet' type='text/css' href='style/stylesheet.css'/>
<script type='text/javascript' src='script/script.js'></script>
</head>
<body>
<div id="header">
<h2><br/>Select a Destination</h2>
</div>
<div class="left">
<p>Departing: <input type="text" id="departing"></p>
</div>
<div class="right">
<p>Returning: <input type="text" id="returning"></p>
</div><br/>
<div id="main">
<div class="ui-widget">
<label for="tags">Destination: </label>
<input id="tags">
<button>Submit</button>
</div>
</body>
</html>
查询:
// JavaScript Document
$(document).ready(function() {
$("#departing").datepicker();
$("#returning").datepicker();
$("button").click(function() {
var departing = $("#departing").val();
var returning = $("#returning").val();
var places = ["Canada","China","Chicago","Japan","Germany","London","Moskow","Paris","Phillipins","India","Russia","Srilanka"];
$("#tags").autocomplete({
source: places,
select: function(event, ui) {
$('#tags').text(ui.item.value);
}
});
if (departing === "" || returning === "") {
alert("Please select departing and returning dates.");
} else {
confirm("Would you like to go to " + ???? + " on " + departing + " and return on " + returning + "?");
}
});
});