我试图弄清楚为什么当我从 HTML 转到我的 Backbone JS 文件时 e.target.getAttribute('data-text') 的值变为空。
HTML:
<script type="text/template" id="lesson-template">
<span id="lesson-title"><%= tracks[0].title %></span>
<select class="sel">
<% _.each(tracks, function(track) { %>
<option value = "<%= track.text %>" data-text="<%= track.title %>"><%= track.title %></option>
<% }); %>
</select>
<p id="tracktext"><%= tracks[0].text %></p>
</script>
JS:
window.LibraryLessonView = LessonView.extend({
events: {
"change .sel " : "changeText"
},
changeText: function(e) {
alert(e.target.getAttribute('data-text')); //I am getting a null value here!
document.getElementById("lesson-title").innerHTML= e.target.getAttribute('data-text'); //I am getting a null value here as well
document.getElementById("tracktext").innerHTML= e.target.value;
}
任何澄清或帮助将不胜感激!