Примечание:
this.tags = ['youtube-cors-upload']
Примечание this.tags
- это Array
. Если вы перезапишите это с value
из input
, вместо этого оно станет String
. Вы уверены, что это то, что вы хотите / нужно?
Если, однако, ваша проблема проста, как вы описываете, решение, подобное этому должно работать:
var mytags = document.getElementById('mytags');
var btn = document.getElementById('btn');
var getAttrValue = document.getElementById('getAttrValue');
btn.addEventListener('click', function() {
// this reads whatever is currently in the input
alert(mytags.value);
})
getAttrValue.addEventListener('click', function() {
// this reads whatever is set in the HTML attribute value on the element
alert(mytags.getAttribute('value'));
})
<div>
<label for="mytags">Add tags:</label>
<input name="mytags" id="mytags" type="text" value="1111, 2222, 3333,">
<button id="btn">Get Tags value from input</button>
<button id="getAttrValue">Get the attribute value instead of the property value</button>
</div>
Если вам нужно проанализировать поле ввода, чтобы каждый разделенный запятыми текст становился элементом массива в this.tags
, это то, что вам нужно сделать:
var tags = ['whatever-this-is'];
var tags2 = ['whatever-this-is'];
var mytags = document.getElementById('mytags');
var btn = document.getElementById('btn');
btn.addEventListener('click', function() {
// this reads whatever is currently in the input
// and splits the values into an array
tags = mytags.value.replace(/ /g, '').split(',');
// if all you want is an array with one element
// that is whatever was in the input, do this:
tags2 = [mytags.value];
console.log(tags);
console.log(tags2);
})
<div>
<label for="mytags">Add tags:</label>
<input name="mytags" id="mytags" type="text" value="1111, 2222, 3333,">
<button id="btn">Get Tags value from input and put them in tags array</button>
</div>
Если ваша проблема в чем-то другом, вам нужно добавить больше информации к вашему вопросу, и я постараюсь изменить свой ответ соответствующим образом.