2015-09-19 84 views
2

这里HTML是我输入JS显示,而不是输入值

<input type="text" class="ChampionInput" list="champions" name="champion[]"`placeholder="Champion" required> 

这里的就是我的js

document.forms["first_form_champions"].oninput = function(e) { 
    var champion = this["champion[]"]; 
    console.log(champion); 
}; 

我想在的console.log显示(冠军)值输入

+0

您正在引用该元素,因此您在登录时获取该元素。 – epascarello

回答

0

Working fiddle

你有要添加.value

this["champion[]"].value; 

希望这会有所帮助。

+0

我已经尝试过,我得到一个错误this.champion []。val不是一个函数 – Higeath

+0

jQuery解决方案是错误的。这是一个你引用的DOM元素,而不是一个jQuery对象。 – epascarello

+0

好的,更新了我的答案。 –

相关问题