我試圖用indexOf
創建合理數量的驗證。Javascript indexOf未返回結果
save()
是一個按鈕的onclick
屬性。
saveDirectionsForm
是文本輸入的id
。
result
是空白段落的id
。
這是我的代碼到目前爲止。當我點擊save()
時,爲什麼沒有呈現?
<!DOCTYPE html>
<html>
<head>
<title>autoComplete</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link rel="stylesheet" href="bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="autocomplete.css" type="text/css">
<script src="jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="masterControls">
<input name="origin-input" id="origin-input" class="controls" type="text"
placeholder="Enter an origin location">
<input name="destination-input" id="destination-input" class="controls" type="text"
placeholder="Enter a destination location">
<div id="mode-selector" class="controls">
<input type="radio" name="type" id="changemode-walking">
<label for="changemode-walking">Walking</label>
<input type="radio" name="type" id="changemode-bicycling" checked="checked">
<label for="changemode-bicycling">Bicycling</label>
<!-- <input type="radio" name="type" id="changemode-transit">
<label for="changemode-transit">Transit</label> -->
<input type="radio" name="type" id="changemode-driving">
<label for="changemode-driving">Driving</label> |
<label for="tolls">Avoid Tolls: </label>
<input id="tolls" type="checkbox" name="tolls" onchange="switchTolls(this)" checked="checked"> |
<button id="restartMap" class="btn btn-default btn-xs" style="height:80%;top:0;margin-bottom:6px;" onclick="restartMap()" type="button">Restart</button>
</div>
</div>
<div id="saveMapAlert" style="display:none;" class="alert alert-success alert-dismissible" role="alert">
<button id="saveMapAlertClose" type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Nice route!</strong> Do you want to save these directions? <span class="label label-default" id="yesAlert" onclick="yesAlert()">Yes!</span> <span class="label label-danger" id="noAlert" onclick="noAlert()">No!</span>
</div>
<div id="saveDirectionsWrapper" class="col-lg-6" style="display:none;margin-bottom:20px;width:25%;">
<div class="input-group">
<input type="text" class="form-control" placeholder="Email Address" required="required" />
<span class="input-group-btn">
<button id="saveDirectionsForm" onclick="save()" class="btn btn-default" type="button">Send!</button>
<!-- <button id="saveDirectionsForm" onclick="saveDirectionsForm()" class="btn btn-default" type="button"><span class="glyphicon glyphicon-ok"></span></button> -->
</span>
</div><!-- input-group -->
</div><!-- col-lg-6 && saveDirectionsWrapper -->
<div id="saveMapAlert2" style="display:none;" class="alert alert-danger alert-dismissible" role="alert">
<button id="saveMapAlertClose2" type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Oh snap!</strong> Blah blah!
</div>
<p id="result"></p>
<div id="map"></div>
<div id="panelWrapper">
<div id="panel" style="height:100%;width:100%;float:right;"></div>
</div>
<script>
function save() {
var emailString = document.getElementById('saveDirectionsForm').value;
if (emailString.indexOf("@") > 0) {
document.getElementById("result").innerHTML = "YES";
}
};
</script>
你檢查什麼價值? – Grundy
'saveDirectionsForm'好像這是一個表單ID,你需要使用電子郵件字段ID –
是INPUT字段的ID:** saveDirectionsForm **? –