Imagebutton JS swap在webkit/phonegap上不起作用

Imagebutton JS swap dosen´t work on webkit/phonegap?

本文关键字:phonegap 不起作用 webkit JS swap Imagebutton      更新时间:2023-09-26

我想让一个简单的imagebutton在Phonegap中工作。我想在点击时交换图像,并在短时间后转发到位置。

所以我已经试过了:

function highl(Bildname,BildURL,Link) {
document.images[Bildname].src = BildURL;
window.setTimeout(forward,1000);
function forward() {
window.location = Link;
}
}
HTML中的

就是这样的链接:

<a href="javascript:highl('level01','level1h.png','test.html')"><img name="level01" src="level1.png" border="0"></a>

在我的Moz中工作得很好,但在Webkit/phonegap中不行(swap不向前工作很好)。

有人能帮忙吗?

Webkit不支持DOM属性突变(见问题8191)标记不会修复。可能有你的问题的链接。

作为一种解决方法,我认为您应该简单地删除DOM节点的内容,并创建一个新的图像节点。

编辑:带代码

您需要识别容器。另外,我设置了href,这样我禁用了javascript,链接仍然可以跟随。如果启用了javascript, return false会告诉浏览器不要跟随该链接。

<a href="test.html" onClick="return highl(this, 'level1h.png', 'test.html');">

javascript。我已经内联了forward,因为它很短,但你不需要。

function highl(el, imgURL, link) {
  var img =  new Image();
  img.src = imgUrl;
  // remove current image. TODO ensure firstChild is not null?
  el.removeChild(el.firstChild);
  // place new image
  el.append(img);
  setTimeout(function() {window.location=link;}, 1000);
  return false;
}