-1

此 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 + "?");
        }
    });
});
4

1 回答 1

1

怎么样

 confirm("Would you like to go to " + jQuery( '#tags' ).val() + " on " + departing + " and return on " + returning + "?");

作用:用户选择目的地后,会显示在 . 所以我们必须读取输入值。

我们通过 jQuery('#tags') 访问 Input-Object。现在我们通过 .val() 请求结果。这将返回输入字段的值。

更多信息: http ://api.jquery.com/val/

啊,因为这可能会引起一些刺激

jQuery( '#tags' ) 等于 $( '#tags' )

于 2013-10-03T07:30:30.560 回答