Javascript indexOf未返回结果
我正在尝试使用Javascript indexOf未返回结果,javascript,html,Javascript,Html,我正在尝试使用indexOf创建合理数量的验证 save()是按钮的onclick属性。 saveDirectionsForm是文本输入的id。 result是空段落的id 这是到目前为止我的代码。为什么单击save()时未呈现任何内容 自动完成 行走 骑自行车 驾驶| 避免使用过路费: | 重新启动 &时代; 路线不错是否要保存这些方向?对不 发送! &时代; 哦,快废话! 函数save(){ var emailString=document.getElementById('saveD
indexOf
创建合理数量的验证
save()
是按钮的onclick
属性。saveDirectionsForm
是文本输入的id
。result
是空段落的id
这是到目前为止我的代码。为什么单击save()
时未呈现任何内容
自动完成
行走
骑自行车
驾驶|
避免使用过路费:
|
重新启动
&时代;
路线不错是否要保存这些方向?对不
发送!
&时代;
哦,快废话!
函数save(){
var emailString=document.getElementById('saveDirectionsForm')。值;
if(emailString.indexOf(“@”)>0){
document.getElementById(“结果”).innerHTML=“是”;
}
};
您检查的值是什么?
saveDirectionsForm
这似乎是一个表单id,您需要使用email字段id作为输入字段的id:saveDirectionsForm?通过将HTML标记包含在问题本身中,这里的评论中进行的问答环节就没有必要了,您现在可能已经得到了答案。考虑编辑你的问题,避免这么多重复的评论!code>saveDirectionsForm是“发送!”按钮的ID,而不是文本输入。您的电子邮件地址输入没有ID。对于按钮的命名和文本输入混乱表示歉意。谢谢您的反馈。不客气
<!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>
<button id="saveDirectionsForm" onclick="save()" class="btn btn-default" type="button">Send!</button>
//you are getting it wrong here
var emailString = document.getElementById('saveDirectionsForm').value;