Onchange open URL via select - jQuery

前端 未结 14 936
长情又很酷
长情又很酷 2020-11-27 10:15

What would be the best way to attach an event so on change of a select option a URL. Store the href in an attr and grab it on change?

相关标签:
14条回答
  • 2020-11-27 11:07

    If you don't want the url to put it on option's value, i'll give u example :

    <select class="abc">
        <option value="0" href="hello">Hell</option>
        <option value="1" href="dello">Dell</option>
        <option value="2" href="cello">Cell</option>
    </select>
    
        $("select").bind('change',function(){
            alert($(':selected',this).attr('href'));
        })
    
    0 讨论(0)
  • 2020-11-27 11:07
    **redirect on change option with jquery** 
    
     <select id="selectnav1" class="selectnav">
                <option value="#">Menu </option>
                <option value="   https://www.google.com">
                Google
                </option>
                <option value="http://stackoverflow.com/">
                  stackoverflow
                </option>
    
             </select>
    
    <script type="text/javascript">
       $(function () {
    
            $('#selectnav1').change( function() {
          location.href = $(this).val();
       });
       });
    </script>
    
    0 讨论(0)
提交回复
热议问题