The behavior of select.remove() method is puzzling
P粉322918729
P粉322918729 2023-08-18 17:05:54
0
1
428

So I work with JavaScript in AgilePoint. I've implemented a function that removes a specific option from a dropdown menu, but the end result is very strange. Here is sample code: enter image description here

So here I have set a simple condition, if the condition is true, I want to remove the first option, the third and the fourth option. But in the end, it only removed the first and fourth options, leaving the third option still there. enter image description here

The last option also needs to be removed, but I don't understand why it ignores the second line.

P粉322918729
P粉322918729

reply all (1)
P粉818125805

The reason is that if you run the following code to remove the 0th element:

select.remove(0);

The 2nd and 3rd elements will no longer be the 2nd and 3rd, but become the 1st and 2nd because the 0th element has been removed.

The quick solution is to remove from the largest index to the smallest index:

select.remove(3); select.remove(2); select.remove(0);
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!