-2
在html文檔中,「id」是「myForm」。 main.js文件鏈接在底部。 我在做什麼錯?未捕獲TypeError:無法讀取null的屬性'addEventListener'?
我一直在尋找一個答案,但似乎我
- 必須在HTML文件中的ID DOM後
<div class="container">
<div class="header clearfix">
<nav>
</nav>
<h3 class="text-muted">Bookmarker</h3>
</div>
<div class="jumbotron">
<h2>Bookmark Your Favorite sites</h2>
<form id="myform">
<div class="form-group">
<label>Site Name</label>
<input type="text" class="form-control" id="siteName" placeholder="Website Name">
</div>
<div class="form-group">
<label>Site Url</label>
<input type="text" class="form-control" id="siteUrl" placeholder="Website URL">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<div class="row marketing">
<div class="col-lg-12">
<div id="bookmarksResults"></div>
</div>
</div>
<footer class="footer">
<p>© 2017 Bookmarker, Inc.</p>
</footer>
</div> <!-- /container -->
<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="js/main.js"></script>
// Listen for formsubmit
document.getElementById('myForm').addEventListener('submit', saveBookmark);
function saveBookmark(){
console.log('It Works');
}