-1
此HTML代碼用於爲旅行選擇日期和目的地。我想在自動完成功能之外顯示我的結果(目的地)。如何在自動填充功能之外顯示Jquery自動填充結果
如何調用confirm
框中的自動完成結果(檢查在jquery中的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>
的Jquery:
// 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 + "?");
}
});
});
由於一噸,它的工作!你能否對你的答案提供一點洞察力,因爲jquery對我來說是新的。 – Saurav
用一些信息更新了我的答案。 – websupporter