以下是我的代碼,我試圖顯示div內的所有元素。 但是我以一個意想不到的結果登陸了。爲什麼選擇div無法正常工作?
的index.php: -
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="jspage.js"></script>
</head>
<body>
<div class="tab-pane fade in active" id="step1">
<fieldset>
<legend><i class="fa fa-id-card" aria-hidden="true"></i> Personal Details</legend>
<div class="form-inline">
<label for="stutitle">Title</label>
<span style="color: red; font-weight:bold;"><big>*</big></span>
<select id=" Title" name="Title" class="imp form-control" >
<option value="">Please select...</option>
<option value="Mr">Mr</option>
<option value="Miss">Miss</option>
</select>
<label for="stufname">Firstname</label>
<span style="color: red; font-weight:bold;"><big>*</big></span>
<input id=" Firstname" name="First Name" placeholder="First name" class="imp form-control" >
<label for="stusname">Surname</label>
<span style="color: red; font-weight:bold;"><big>*</big></span>
<input id=" Surname" name="Surname" placeholder="Surname" class="imp form-control" >
<br><br>
</div>
</fieldset>
</div>
<input type="submit" value="submit" name="app_submit" />
</body>
</html>
jspage.js: -
$(document).ready(function() {
$('input[name="app_submit"]').click(function() {
$('div[id="step1"] input,select').each(function() {
console.log("Step1: "+$(this).attr('name'));
});
$('div[id="step2"] input,select').each(function() {
console.log("Step2: "+$(this).attr('name'));
});
});
});
在這裏,我發現了以下的輸出:
Step1: Title
Step1: First Name
Step1: Surname
Step2: Title
的DIV ID作爲第二步沒有按即使存在,它仍然會讓我輸出第2步。由於我對這個新手,我無法弄清楚我做錯了什麼。 如果程序遵循正確與否,有人可以指導我嗎? 這裏我的錯誤是什麼? 您的輸入將是一個很大的幫助。 在此先感謝。
它的工作原理(Y),謝謝:) – Devanshi
這是男人的事做好 –