【问题标题】:How to use a image as a submit button, to submit itself to server?如何使用图像作为提交按钮,将自身提交到服务器?
【发布时间】:2012-12-03 13:06:09
【问题描述】:
<form name="myform" action="app.py">
<div class="box">
<input type="image" id="image" src="http://mychickencoopplans.files.wordpress.com/2010/12/happy-chicken.jpg" >
</div>
</form>
我正在尝试创建一张图片,点击后将其 src 发送到服务器 (app.py)?我将如何使用 HTML/javascript 完成此操作?谢谢。
【问题讨论】:
标签:
javascript
html
image
forms
src
【解决方案1】:
试试:
<form name="myform" action="app.py">
<input type="hidden" value="" id="hidSrc">
<div class="box">
<input type="image" id="image" onclick="document.getElementById('hidSrc').value = this.src;document.myform.submit();" src="http://mychickencoopplans.files.wordpress.com/2010/12/happy-chicken.jpg" >
</div>
</form>
【解决方案2】:
你可以试试这个
<form name="myform" action="app.py">
<input type="hidden" value="" id="hidimgSrc">
<div class="box">
<input type="image" id="image" onclick="document.getElementById('hidimgSrc').value = this.src;document.getElementById('myform').submit();" src="http://mychickencoopplans.files.wordpress.com/2010/12/happy-chicken.jpg" >
</div>
</form>