【问题标题】:Page redirect to next page页面重定向到下一页
【发布时间】:2013-05-31 17:47:33
【问题描述】:

我在我的应用程序中使用了地图 api。对于选择标记,名为“Add marker”和“Refresh map"”的按钮用于刷新地图。我正面临着这里。

保存数据后,保存按钮将重定向到下一页。在我的情况下,“添加标记”,"Refresh map" 都在执行保存按钮工作,如果我按下 "Add marker" 而不是显示标记,页面被重定向到下一页。这是在使用 </form> 后发生的。在此处查看我的模板,

<form method="POST" action="/member/where/" >
{% csrf_token %}
<td colspan="2" class="incident-type" style="padding-left:25px">
  {% for location in locationList%}
  {% if location.parent_location_id == None %}
  <h1>{{location.title}}</h1>
  {% endif %}
{% endfor %}
<p>
<span class="map_buttons" >{% include "buttons/refreshmap.html" %}</span> <span class="map_buttons" style="margin-left:20px;">{% include "buttons/addmarker.html" %} </span>
</p>
<p id=ir-nextbtn>{% include "buttons/next.html" %}</a></form></p>

刷新标记.html

<button type="submit" title="Refresh map"  class="map_buttons button_style">Refresh map</button>

addmarker.html

<button type="submit" title="Add marker"  class="map_buttons button_style">Add marker</button>

需要澄清这个问题。

【问题讨论】:

  • 你能粘贴按钮的html吗?两个按钮都是提交按钮吗?
  • @Rhea,均为 html,已更新。

标签: python html django django-forms django-templates


【解决方案1】:

问题是因为这两个按钮的类型都是submit,当您单击其中一个按钮时,表单就会被提交。结果,页面被重定向到 action 的形式,即 /member/where/

试试这个:- 保持原样刷新,

  <button type="submit" title="Refresh map"  class="map_buttons button_style">Refresh map</button>

并添加

 <button onClick=somefuntion(this)' title="Add marker"  class="map_buttons button_style">Add   marker</button>

让一些功能完成需要

<script>
function somefuntion(button){
    // your code
   document.forms[0].submit() // this will submit your form
 }
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 2015-10-22
    • 2014-05-17
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 2014-02-22
    相关资源
    最近更新 更多