焦点功能不会触发两次
const Arrays = new Array();
Arrays [0] = obst;
Arrays [1] = Obst;
Arrays [2] = gemüse;
Arrays [3] = Gemüse;
var select_select_array = document.createElement('select');
select_select_array.id = 'Select_array_delete';
select_select_array.autofocus = true;
console.log(select_select_array.autofocus);
fieldset_select_array.appendChild(select_select_array);
select_select_array.addEventListener('change', array_selected);
select_select_array.addEventListener('change', set_array_name);
select_select_array.addEventListener('focus', array_selected);
select_select_array.addEventListener('focus', set_array_name);
function set_array_name()
{
list_choice = select_select_array.value;
for (let i = 0; i <= Arrays.length; i = i + 2)
{
if (list_choice === Arrays[i])
{
select_item_to_delete.innerHTML = '';
array_name = list_choice.charAt(0).toUpperCase() + list_choice.slice(1);
selected_array_delete = eval(array_name);
for (let i2 = 0; i2 < selected_array_delete.length; i2++)
{
item_to_delete = document.createElement('option');
item_to_delete.innerHTML = selected_array_delete[i2];
item_to_delete.value = selected_array_delete[i2];
item_to_delete.id = 'Opt_' + selected_array_delete[i2];
select_item_to_delete.appendChild(item_to_delete);
}
}
}
}
https:// https://learning-byby-by-by-doing.netlify。应用/学习%20BY%20Doing%20JavaScript/arrays.html
所以我有以下问题,我是JavaScript的新手,所以请原谅我的不良编码,
之后的Szenario:我单击一个按钮(“Löschen”),生成一个接口,在第一个选择是自动进行的,自动对焦触发事件,该事件告诉JS选择了哪个数组,以便JS可以决定第二个选择元素,必须显示哪些选项,所有这些选项都很好,所有这些都很好
。单击主菜单按钮(右下方的一个按钮,如果您在此问题开始时打开了所提供的站点。然后,您再次单击“Löschen”,现在应该通过JS重建整个站点,因为我首先清空了内部HTML网站通过=''
因此,在我的理论中,所有元素都会再次创建,具有相同属性等,但是当您在第二次选择第二次选择元素时单击“löschen”时,不会自动显示任何选项,除非您手动将第一个选择元素。
这是怎么发生的?有解决方案吗?
多谢 :)
const Arrays = new Array();
Arrays [0] = obst;
Arrays [1] = Obst;
Arrays [2] = gemüse;
Arrays [3] = Gemüse;
var select_select_array = document.createElement('select');
select_select_array.id = 'Select_array_delete';
select_select_array.autofocus = true;
console.log(select_select_array.autofocus);
fieldset_select_array.appendChild(select_select_array);
select_select_array.addEventListener('change', array_selected);
select_select_array.addEventListener('change', set_array_name);
select_select_array.addEventListener('focus', array_selected);
select_select_array.addEventListener('focus', set_array_name);
function set_array_name()
{
list_choice = select_select_array.value;
for (let i = 0; i <= Arrays.length; i = i + 2)
{
if (list_choice === Arrays[i])
{
select_item_to_delete.innerHTML = '';
array_name = list_choice.charAt(0).toUpperCase() + list_choice.slice(1);
selected_array_delete = eval(array_name);
for (let i2 = 0; i2 < selected_array_delete.length; i2++)
{
item_to_delete = document.createElement('option');
item_to_delete.innerHTML = selected_array_delete[i2];
item_to_delete.value = selected_array_delete[i2];
item_to_delete.id = 'Opt_' + selected_array_delete[i2];
select_item_to_delete.appendChild(item_to_delete);
}
}
}
}
https://learning-by-doing.netlify.app/learning%20by%20doing%20javascript/arrays.html
so i got the following problem , i am new to Javascript , so please excuse my bad coding,
following szenario: i click a button ("Löschen") , an interface gets generated , where the first select is autofocused , the autofocus triggers an event , which tells js which array is selected , so that js then can decide on the second select element , which options have to be shown , all good so far
you click the main menu button (the one on the bottom right if you open the site supplied at the start of this question. then you click 'Löschen' again , the whole site should now be rebuild by js since i first emptyed the inner HTML of the site via = ''
so in my theory , all elements get created again, with same attributes and so on , yet when you click "Löschen" the second time the second select Element , wont automatically show any options , unless you manually focus the first select element.
how does this happen? any solutions?
Thanks a lot :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自动对焦页面加载时将元素聚焦。每当需要使用 focus focus 这样的方法:elem.focus();
因此,在您的情况下,您需要手动将其渲染后集中精力
Autofocus focuses the element when the page loads. You can focus your element with javascript whenever you need with focus method like this: elem.focus();
So, in your case you need to focus your element manually after it is rendered