No touch event for li tag

。_饼干妹妹 提交于 2019-12-12 01:07:27

问题


I use touch monitor and html page (MS Windows 7 Pro Eng, IE8). And I discovered that touch fires when text area of li tag is tapped and the rest is ignored.

How change it so even if user tap on white/non-text area of the li it fires as it should.

<link href="css/bootstrap.min.css" rel="stylesheet" />    
<script src="jquery-1.11.3.min.js"  type="text/javascript"></script>
<script src="jquery.mobile-1.4.5.min.js" type="text/javascript"></script>

<ul class="nav" id="mainList">
        <li class="touchedLi stripe-even" id="item0"><a  href="#">Club Yellow 1</a></li>
        <li class="touchedLi stripe-odd" id="item1"><a href="#">Club Yellow 2</a></li>
        <li class="touchedLi stripe-even" id="item2"><a  href="#">Club Yellow 3</a></li>
    </ul>

CSS

li.stripe-even {
    background-color: #FFF1ED;
    list-style-type: none;
}

li.stripe-odd{
  background-color: #F2FFED;
  list-style-type:none;
}

ul.mainList li:hover{
background-color: yellow;
}

#mainList a:active {
    color: white;
    background-color: orange;
}

#mainList>li>a {
    display: block;
}

li.stripe-even {
background-color: #FFF1ED;
list-style-type: none;
}

li.stripe-odd{
  background-color: #F2FFED;
  list-style-type:none;
}

 ul.mainList li:hover{
    background-color: yellow;
    }
    
    #mainList a:active {
    	color: white;
        background-color: orange;
    }
    
    #mainList>li>a {
        display: block;
    }

    #mainList>li {
        display: block;
    }

 #mainList>li {
    display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 


<ul class="nav" id="mainList">
            <li class="touchedLi stripe-even" id="item0"><a  href="#">Club Yellow 1</a></li>
            <li class="touchedLi stripe-odd" id="item1"><a href="#">Club Yellow 2</a></li>
            <li class="touchedLi stripe-even" id="item2"><a  href="#">Club Yellow 3</a></li>
        </ul>

回答1:


So I found working solution

Nothing is working but only &nbsp;

So the li tag should look like this

<ul class="nav" id="mainList">
            <li class="touchedLi stripe-even" id="item0"><a  href="#">Club Yellow 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
            <li class="touchedLi stripe-odd" id="item1"><a href="#">Club Yellow 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
            <li class="touchedLi stripe-even" id="item2"><a  href="#">Club Yellow 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
</ul>

And then the area of &nbsp; is a touchable area! :)

How you are gonna add &nbsp; it depends of your needs.




回答2:


What is your CSS? Try adding display: block to the a tag.



来源:https://stackoverflow.com/questions/37468978/no-touch-event-for-li-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!