[英]how to change image after clicking submit button?
I want a code for questionnaire.我想要一个问卷代码。 with each question answered (text format) image change with the click of submit and progress bar increase.
随着每个问题的回答(文本格式),图像随着提交的点击而改变,进度条增加。
I have to change 3 things with one click.我必须一键更改 3 项内容。
<script>
var img_array = ['placehold.it/100x100/green';, 'placehold.it/100x100/blue';, 'placehold.it/100x100/red'];
i = 0;
function myFunction() {
i++;
document.getElementById("myImg").src = img_array[i]; if (i == img_array.length - 1) { i = -1; }
}
</script>
If you want to change the image for image then this is the sample如果您想更改图像的图像,那么这就是示例
document.getElementById('theImage').src="image.png";
If you want to change the background image of a button then this is the sample如果您想更改按钮的背景图像,那么这就是示例
document.getElementById("button").style.backgroundImage = "url('http://image/1917/crossn.png')";
button.style.backgroundRepeat = "no-repeat";
I have to change 3 things with one click.我必须一键更改 3 项内容。 question image progress bar
问题图片进度条
Sample html code:示例 html 代码:
<div id="myQuestion">Qeuestion1</div>
<img src="test" id="myImg" /><br/>
<progress id="progressId" value="0" max="100"></progress><br/>
<button id="buttonId" onClick="myFunction()">submit</button>
Sample javascript code:示例 javascript 代码:
$(document).ready(function(){
var qus_array = ['Question1','Question2','Question3']
var img_array = ['placehold.it/100x100/green', 'placehold.it/100x100/blue', 'placehold.it/100x100/red'];
var i = 0;
$('button').click(function(){
i++;
document.getElementById("myQuestion").innerHTML = qus_array[i];
document.getElementById("myImg").src = img_array[i];
document.getElementById("progressId").value = 33*i;
if (i == img_array.length - 1) { i = -1; }
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.