您好我的html和js有问题,我尝试做一个“欢迎”,检查输入框是否有什么会迎接你并写下你的名字,如果什么也没有,它根本不应该问候你。但是它没有按我的意愿工作。它总是迎接你,甚至不在这里写你的名字。有谁能够帮我 ?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>something</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery.mobile-1.4.2.js"></script>
<script src="greeter.js"></script>
<link rel="stylesheet" href="themes/vsb-1.4.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.structure-1.4.2.min.css" />
</head>
<body>
<div data-role="page" id="page1" data-theme="c" data-title="Second example">
<div data-role="header">
<h1>TAMZ1 (Greetings)</h1>
</div>
<div class="ui_content" role="main">
<div data-role="fieldcontain">
<label for="fullName">Enter your name:</label>
<input type="text" id="fullName" placeholder="e.g. J. Doe" />
</div>
<a data-role="button" data-icon="alert" id="greeting" data-rel="dialog" href="#grdialog">Greet me!</a>
</div>
</div>
<div data-role="dialog" id="grdialog" data-title="Greetings">
<div data-role="header">
<h1>Greetings!</h1>
</div>
<div data-role="content">
<div id="greet_text"></div>
</div>
<div data-role="footer">
<a data-role="button" id="back" data-icon="back" data-rel="back" href="history.back()">Back</a>
</div>
</div>
</body>
</html>
$(document).on("pagecreate", "#page1", function(event){
$("greeting").click(function(e){
if ($("#fullName").val() === undefined || $("#fullName").val() === "") {
e.preventDefault();
alert("You did not fill your name!");
}
else{
$("#greet_text").text("Greetings, " + $("#fullName").val() + '!');
}
});
});
答案 0 :(得分:1)
您正在寻找问候元素,而不是具有ID
的元素$("greeting").
需要
$("#greeting").