开发者

How stay at the same location after updating the page?

开发者 https://www.devze.com 2023-04-11 03:01 出处:网络
I have the following code inside <table> tags. item is the result of the query. When I click on the \"(hide)\" link display becomes \"false\" and the code below is executed. This gets the item t

I have the following code inside <table> tags. item is the result of the query. When I click on the "(hide)" link display becomes "false" and the code below is executed. This gets the item that I want to hide from database by id and then changes display property from "True" to "False" and writes it to database. The problem is that since the link refers to the same page (/useradminpage) after the click, the page returns to the top. If the item is in page 2, and I click "(hide)", it returns to the top of page 1. How do I fix this so that after I click the "(hide)" link it stays on the same place? I was trying to do this with javascript but I could not make it work. Thanks.

    ...
    for item in e:
        main_id = item.key().id()
开发者_JS百科        self.response.out.write("""
        <tr>
        ...
        <a href="/useradminpage?main_id=%s&display=false"> 
        <span class="small">(hide)</span></a>
        ...
        </td>
        </tr>""" % tuple([...main_id...]))

        #try to prevent default behavior; but this does not work
        self.response.out.write("""<script>
        $("a").click(function (evt){
        evt.preventDefault();
        }</script>""")

    self.response.out.write("""</tbody></table>""")    

    if display == "false":
        main_id = self.request.get("main_id")
        k = Main.get_by_id(int(main_id))
        k.display = False
        k.put()


Taking a stab in the dark and guessing you're referring to this?

$("a").click(function (evt){
    evt.preventDefault();
}

Stops the page jumping back to the top

0

精彩评论

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

关注公众号