我确定这是一个非常新手的问题,但我最近才开始为包含客户端表单验证的表单输入一些代码。在我开始尝试为此编写 javascript/jQuery 代码时,我的 append() 方法并没有产生任何可见的结果。我已经尝试隔离 append() 语句,将 id 更改为 class,查看我已将段落附加到 div 的旧代码无济于事。非常欢迎所有建议和提示。
html5代码:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title></title>
</head>
<body>
<form>
First name: <input id = "firstName" type="text" name="firstname" value="first name"><br/>
Last name: <input id = "lastName" type="text" name="lastname" value="last name"><br/>
<div class = "text"><textarea></textarea>
<p></p> <input type="radio">Master Race Python User
<p></p> <input type="radio">Imperial Ruby Scum
</div>
<div class = "languages">
<h3>Languages Known</h3>
<input type="checkbox">Python
<input type="checkbox">Ruby
<input type="checkbox">html
<input type="checkbox">CSS
<input type="checkbox">Javascript
<input type="checkbox">jQuery
<input type="checkbox">Other
<input type="checkbox" checked>Filthy casual
<p><input type ="submit"></p>
</div>
<div id = "check">
<p><strong><em>Check</em></strong></p>
</div>
<div class = "response">
<p></p>
</div>
</form>
</body>
</html>
CSS 代码:
.text {
background-color:#00ffff;
border:solid black;
border-radius:3%;
box-shadow: 5px 5px 5px
}
.languages {
background-color:#FFFF33;
border:solid black;
border-radius:15%;
box-shadow: 5px 5px 5px;
margin-top:10px;
}
#check {
background-color:#ABCDEF;
border:solid black;
width:50px;
margin-left:200px;
margin-top:10px;
}
.response {
border:solid black;
width:190px;
height:50px;
}
Javascript/jQuery:
$(document).ready(function(){
$(".response").append("<p>"+"Nothing to do, eh?" +"</p>")
$("#check").click(function(){
var lastName =("#lastName").val()
if (lastName === ""){
$(".response").append("<p>"+"Please submit a valid entry"+"</p>")
}
})
})