Select tag inside hyperlink problem

前端 未结 2 1225
清酒与你
清酒与你 2021-01-16 06:31

I have simplified my page and here what I have:




&l         


        
相关标签:
2条回答
  • 2021-01-16 06:51

    The problem with your approach: everything is contained in this link element. So theoretically, a browser is right to assume that anything that gets clicked inside this A-tag is clicking the link. Even thought this may work differently for some browsers, and lead to the behaviour you would like, I would doubt that the behaviour is consistent over all user agents. Hence I don't see how there is any way to make this work reliably without getting rid of the A-element, respectively moving the A-element so its only around the image (which is the behaviour you desire):

    <a href="#############">
       <img src="preview_image" />
    </a>
    <div>
       <input type="text" value="" />
       <select>
                <option value="default" selected>choose</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
       </select>
    </div>
    
    0 讨论(0)
  • 2021-01-16 06:54

    Even if I don't know, what you need your entire <a><div>... construct for, in any case you should put your script into a ready() block, so that it executes when the page is loaded:

    $(document).ready(function(){
    
       $('div').click(function(){
            return false;
       });
    
    });
    
    0 讨论(0)
提交回复
热议问题