开发者

How can we exclude some positions in list item while dropping objects in the list using Jquery

开发者 https://www.devze.com 2023-02-10 03:25 出处:网络
In Jquery I want small div tag boxes to be added in the list item. But at that some positions in the list item should be disabled. e.g. if i have 5 items, then I can drag and drop them in the li开发者

In Jquery I want small div tag boxes to be added in the list item. But at that some positions in the list item should be disabled. e.g. if i have 5 items, then I can drag and drop them in the li开发者_运维知识库st but excluding the 2nd position in the list.


When you are looping through the list, you can check the index of the list items and then decide whether you want to exclude that item or not. For example, if you didn't want to perform some action on the second list item, you can do the following:

$( 'ul li' ).each(function()
{
    if( $(this).index() != 1 )
    {
        // Perform some action
    }
});

Remember that indexes begin at 0, so the second item has an index of 1, the 10th item has an index of 9 etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号