How to redirect on another page and pass parameter in url from table?

后端 未结 4 1625
花落未央
花落未央 2020-12-03 03:09

How to redirect on another page and pass parameter in url from table ? I\'ve created in tornato template something like this

相关标签:
4条回答
  • 2020-12-03 03:17

    Here is a general solution that doesn't rely on JQuery. Simply modify the definition of window.location.

    <html>
       <head>
          <script>
             function loadNewDoc(){ 
                var loc = window.location;
                window.location = loc.hostname + loc.port + loc.pathname + loc.search; 
             };
          </script>
       </head>
       <body onLoad="loadNewDoc()">
       </body>  
    </html>
    
    0 讨论(0)
  • 2020-12-03 03:35

    Set the user name as data-username attribute to the button and also a class:

    HTML

    <input type="button" name="theButton" value="Detail" class="btn" data-username="{{result['username']}}" />
    

    JS

    $(document).on('click', '.btn', function() {
    
        var name = $(this).data('username');        
        if (name != undefined && name != null) {
            window.location = '/player_detail?username=' + name;
        }
    });​
    

    EDIT:

    Also, you can simply check for undefined && null using:

    $(document).on('click', '.btn', function() {
    
        var name = $(this).data('username');        
        if (name) {
            window.location = '/player_detail?username=' + name;
        }
    });​
    

    As, mentioned in this answer

    if (name) {            
    }
    

    will evaluate to true if value is not:

    • null
    • undefined
    • NaN
    • empty string ("")
    • 0
    • false

    The above list represents all possible falsy values in ECMA/Javascript.

    0 讨论(0)
  • 2020-12-03 03:38

    Do this :

    <script type="text/javascript">
    function showDetails(username)
    {
       window.location = '/player_detail?username='+username;
    }
    </script>
    
    <input type="button" name="theButton" value="Detail" onclick="showDetails('username');">
    
    0 讨论(0)
  • 2020-12-03 03:38

    Bind the button, this is done with jQuery:

    $("#my-table input[type='button']").click(function(){
        var parameter = $(this).val();
        window.location = "http://yoursite.com/page?variable=" + parameter;
    });
    
    0 讨论(0)
提交回复
热议问题