问题第1部分(为了使这更明显的,而不是迷失在评论):
“手机浏览器”,如触摸屏输入控制的浏览器显然不具备鼠标交互事件。相反,他们通常实现触摸屏特定的类似事件,在你的情况下是ontouchstart()和ontouchend()。
问题2部分:
而不是为每个图像发射click事件编程,以显示所有图片我会做这样的事情:
<html>
<head>
<script type="text/javascript">
var images = [{"DomId" : "Swapimage1", "RegSrc" : "image1.jpg", "ClkSrc" : "image2.jpg"},{"DomId" : "Swapimage2", "RegSrc" : "image3.jpg", "ClkSrc" : "image4.jpg"}];
function LoadImages() {
for (var image in images) {
document.getElementById(images[image].DomId).src = images[image].RegSrc;
}
}
function SwapImage(imageObject, imageId, isClicked) {
imageObject.src = isClicked ? images[imageId].ClkSrc : images[imageId].RegSrc;
}
function SwapAllImages(isClicked) {
for (var image in images) {
document.getElementById(images[image].DomId).src = isClicked ? images[image].ClkSrc : images[image].RegSrc;
}
}
</script>
</head>
<body OnLoad="LoadImages()">
<img alt="Click" id="Swapimage1" onmousedown="SwapImage(this, 0, true)" onmouseup="SwapImage(this, 0, false)" ontouchstart="SwapImage(this, 0, true)" ontouchend="SwapImage(this, 0, false)" width="400" height="400" />
<img alt="Click" id="Swapimage2" onmousedown="SwapImage(this, 1, true)" onmouseup="SwapImage(this, 1, false)" ontouchstart="SwapImage(this, 1, true)" ontouchend="SwapImage(this, 1, false)" width="400" height="400" />
<a href="#" id="SwapAllLink" onmousedown="SwapAllImages(true)" onmouseup="SwapAllImages(false)" ontouchstart="SwapAllImages(true)" ontouchend="SwapAllImages(false)">Swap All Images</a>
</body>
</html>
尝试' 2011-05-23 12:34:14
请定义手机浏览器用户?我们在这里谈论触摸屏吗?你有没有尝试触摸和开启事件? – Till 2011-05-23 12:44:51
是的,我主要关注iOS和Android用户。我没有尝试过那些。我现在会。然而,我也想使用通过链接来模拟这个功能来迭代页面上的所有图像并揭示“秘密”图像。 – Frank 2011-05-23 12:50:56