我想将输入框移动到左上角,所以我在js中添加了一个onclick函数:
function moveToLeft(){
var elems = document.getElementsById("inputbox");
for(var i=0;i<elems.length;i++){
elems[i].style.left = "200px"
elems[i].style.top = "80px"
}
}
我的html文件:
<script>{% include "js/move.js" %}</script>
<button id="searchButton" onclick="moveToLeft()"> Search </button>
<div>
<input id="inputbox" type="text" name="search_text" class="form-control">
</div>
在views.py中:
@app.route('/', methods=['GET','POST'])
def index():
data = request.form.get("search_text")
// ...... do sth with data
return render_template("index.html", form=data)
我认为是因为render_template函数重新加载了网页,所以如何使用onclick函数移动元素而不刷新页面?