我正在做一些代码,我希望得到用户引入的输入文本的值
获取值
var inputTextValue = document.getElementsByClassName("something");
alert("inputTextValue.value);
创建输入文字
function createHour(){
var hour = document.createElement("INPUT");
hour.id = "something";
defineButtonHour(hour);
//after: -code to append to div
}
function defineHour(hour) {
hour.className = "something";
}
警报只是打印未定义。
答案 0 :(得分:2)
getElementsByClassName返回一个包含与该类匹配的所有元素的数组,您需要遍历该数组,或者通过提供索引来访问您想要的那个“
POST http://localhost:3000/users/registrations
Content-Type application/vnd.api+json
{
"data": {
"type": "users",
"attributes": {
"email": "neil@examples.com",
"password": "Whatevs",
"password_confirmation": "Whatevs"
}
}
}
你的警报中还有一个额外的分号,不应该在那里
答案 1 :(得分:0)
var inputTextValue = document.getElementsByClassName("something");
返回具有类的所有节点的节点列表。节点列表是一种数组。你可以写:
var inputTextValue = document.getElementsByClassName("something")[0];
如果你能保证至少有一个,你只需要一个。
此外,您的提醒有一个不需要的报价:
alert(inputTextValue.value);