简体   繁体   English

根据按钮的点击次数创建新元素

[英]Create new element according to number of clicks on a button

** **

Short question:How do I programme the html button to show the details af a particular image according to the number of clicks ie if the button is clicked once:show image 1;twice :show image 2 etc; 简短的问题:如何编程html按钮以根据点击次数显示特定图像的详细信息,即是否单击一次按钮:显示图像1;两次:显示图像2等;

** **

Long explanation of question: 问题的详细说明:

So I want to create a html /php/javascript form.Not just the basic html raw form.No, I want it to be able to allow users upload multiple files at once.I want the layout to be that each time a user presses the upload button,a new file can be uploaded with the thumbnail shown ie a rectangle like box surrounding the details of the uploaded file such as : upload form 所以我想创建一个html / php / javascript表单,而不仅仅是基本的html原始表单,不,我希望它能够允许用户一次上传多个文件,我希望布局是每次用户按下时的布局上传按钮,可以上传新文件,并显示缩略图,即围绕上传文件详细信息的矩形框,如: 上传表单

I've tried using javascript to create a new element to contain details of the uploading file including the thumbnail when an upload button is clicked but I have a question: 我尝试使用javascript创建一个新元素来包含上载文件的详细信息,包括当单击上载按钮时的缩略图,但是我有一个问题:

How do I programme the html button to show the details af a particular image according to the number of clicks ie if the button is clicked once:show image 1;twice :show image 2 etc 如何根据点击次数对html按钮进行编程以显示特定图像的详细信息,即是否单击一次按钮:显示图像1;两次:显示图像2等

If you have the same name in the images as the correspondent clicks number, it would be as easy as this: 如果图像中的名称与相应的点击数相同,那么就很容易了:

<button onclick="this.children[0].setAttribute('src', (Number(this.children[0].getAttribute('src').split('.')[0])+1) + '.jpg')">
 <img src="0.jpg"></img>
</button>

Of course, it's cleaner to have the js code in a function, instead there. 当然,在函数中包含js代码会比较干净。

If your images names do not match with the numbers, you can use an associative array or object to get the correct name for each position. 如果图像名称与数字不匹配,则可以使用关联数组或对象为每个位置获取正确的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM