Javascript 每次新的点击都能产生新的图像吗?
我知道如何使用onclick或onMouseOver使图像显示,但如何使每次单击都产生适当的图像,不仅在同一个位置,而且,例如,在其先前外观旁边的一行中?我的想法是:我点击参考1,就会出现一张图片1。然后我点击参考2,一个图片2显示在已经显示的图片1旁边。现在我再次单击reference1,我想看到一行中的图片1,2,1。我该怎么做?我的理想是在填充时看到行滚动,一个删除按钮删除该行中的最后一个图像,甚至使图片从文本字段中跳出,但我可以自己搜索这些图片。我现在最关心的是新点击=新图像。谢谢。假设这是相对简单的-您可以在图像列表中跟踪当前位置,然后创建一个处理当前图像的函数,然后增加此位置。让onClick事件调用这个函数,就可以了 使用JQuery可以在此处查看这方面的示例:Javascript 每次新的点击都能产生新的图像吗?,javascript,html,onclick,Javascript,Html,Onclick,我知道如何使用onclick或onMouseOver使图像显示,但如何使每次单击都产生适当的图像,不仅在同一个位置,而且,例如,在其先前外观旁边的一行中?我的想法是:我点击参考1,就会出现一张图片1。然后我点击参考2,一个图片2显示在已经显示的图片1旁边。现在我再次单击reference1,我想看到一行中的图片1,2,1。我该怎么做?我的理想是在填充时看到行滚动,一个删除按钮删除该行中的最后一个图像,甚至使图片从文本字段中跳出,但我可以自己搜索这些图片。我现在最关心的是新点击=新图像。谢谢。假设
假设这是相对简单的-您可以在图像列表中跟踪当前位置,然后创建一个处理当前图像的函数,然后增加此位置。让onClick事件调用这个函数,就可以了 使用JQuery可以在此处查看这方面的示例: 下面是一个例子
<html>
<head>
<style>
.refimg { width: 100px; height: 100px; }
.choices a { margin-right: 2ex; }
.choices img { display: none; }
#target { display:block; width: 500px; overflow-x: scroll; border: 1px solid black; }
</style>
</head>
<body>
Choices:
<div class="choices">
<a href="#" onclick="return putImage(image1);">ref1</a>
<a href="#" onclick="return putImage(image2);">ref2</a>
<image id="image1" src="image1.gif" class="refimg" />
<image id="image2" src="image2.gif" class="refimg" />
</div>
<br />
Selections: <input type="button" value="Delete" onclick="delImage()" />
<nobr id="target">
</nobr>
<script>
function putImage(src) {
var a = src.cloneNode(true);
a.id = ''; //clear id to prevent duplicate id
target.appendChild(a);
a.scrollIntoView(true);
return false;
}
function delImage() {
var a=target.children;
if (a.length>0) target.removeChild(a[a.length-1]);
}
target.style.height=((target.offsetHeight-target.clientHeight)+100)+'px'; //extend height for scroll bar
</script>
</body>
</html>
.refimg{宽度:100px;高度:100px;}
.choices a{右边距:2ex;}
.choices img{display:none;}
#目标{显示:块;宽度:500px;溢出-x:滚动;边框:1px纯黑色;}
选择:
选择:
函数putImage(src){
var a=src.cloneNode(真);
a、 id='';//清除id以防止重复id
目标:儿童(a);
a、 scrollIntoView(true);
返回false;
}
函数delImage(){
var a=target.children;
如果(a.length>0)target.removeChild(a[a.length-1]);
}
target.style.height=((target.offsetHeight-target.clientHeight)+100)+'px'//滚动条的延伸高度
下面是一个例子
<html>
<head>
<style>
.refimg { width: 100px; height: 100px; }
.choices a { margin-right: 2ex; }
.choices img { display: none; }
#target { display:block; width: 500px; overflow-x: scroll; border: 1px solid black; }
</style>
</head>
<body>
Choices:
<div class="choices">
<a href="#" onclick="return putImage(image1);">ref1</a>
<a href="#" onclick="return putImage(image2);">ref2</a>
<image id="image1" src="image1.gif" class="refimg" />
<image id="image2" src="image2.gif" class="refimg" />
</div>
<br />
Selections: <input type="button" value="Delete" onclick="delImage()" />
<nobr id="target">
</nobr>
<script>
function putImage(src) {
var a = src.cloneNode(true);
a.id = ''; //clear id to prevent duplicate id
target.appendChild(a);
a.scrollIntoView(true);
return false;
}
function delImage() {
var a=target.children;
if (a.length>0) target.removeChild(a[a.length-1]);
}
target.style.height=((target.offsetHeight-target.clientHeight)+100)+'px'; //extend height for scroll bar
</script>
</body>
</html>
.refimg{宽度:100px;高度:100px;}
.choices a{右边距:2ex;}
.choices img{display:none;}
#目标{显示:块;宽度:500px;溢出-x:滚动;边框:1px纯黑色;}
选择:
选择:
函数putImage(src){
var a=src.cloneNode(真);
a、 id='';//清除id以防止重复id
目标:儿童(a);
a、 scrollIntoView(true);
返回false;
}
函数delImage(){
var a=target.children;
如果(a.length>0)target.removeChild(a[a.length-1]);
}
target.style.height=((target.offsetHeight-target.clientHeight)+100)+'px'//滚动条的延伸高度
什么语言?同样,考虑用正确的语言特定标签标记你的问题;这样会得到更快的关注。什么语言?同样,考虑用正确的语言特定标签标记你的问题;这样会得到更快的关注。