Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript <;tr>;onclick可以工作,但我也想要一个视觉效果_Javascript_Android_Html - Fatal编程技术网

Javascript <;tr>;onclick可以工作,但我也想要一个视觉效果

Javascript <;tr>;onclick可以工作,但我也想要一个视觉效果,javascript,android,html,Javascript,Android,Html,在android应用程序中,我有一个tr onclick=“HitRow(this)”;“。。。单击整个表行时转到另一个url。这个很好用 function HitRow(cell,loc) { window.location.href = loc; cell.style.backgroundColor = "red"; } 但是,我还希望在该行上进行可视化单击。我试着用cell.style.backgroundCol

在android应用程序中,我有一个tr onclick=“HitRow(this)”;“。。。单击整个表行时转到另一个url。这个很好用

    function HitRow(cell,loc) 
        { 
        window.location.href = loc;
        cell.style.backgroundColor = "red";
        }
但是,我还希望在该行上进行可视化单击。我试着用cell.style.backgroundColor设置背景色,但在用户导航离开和/或它以令人困惑的方式瞬间闪烁后,这种设置就起作用了

理想情况下,我希望在触摸时更改颜色,在触摸时执行href。这能做到吗

谢谢

您可以尝试:

与此相反:

function HitRow(cell,loc) 
            { 
            window.location.href = loc;
            cell.style.backgroundColor = "red";
            }
试试这个:

function HitRow(cell,loc) 
        { 
        cell.style.backgroundColor = "red";
        window.location.href = loc;

        }

我会使用不引人注目的Javascript,为此:

标记:

<tr data-url="http://www.google.com">

</tr>
var tr = document.querySelector("tr");
tr.addEventListener("touchstart", function() {
    this.style.backgroundColor = "red";
});
tr.addEventListener("touchend", function() {
    window.location.href = this.getAttribute("data-url");
});
如果您有多个
tr
元素,则需要使用
document.querySelectorAll
并循环遍历它们:

var i;
var elements = document.querySelectorAll("tr[data-url]");
for(i=elements.length;i--) {
    var element = elements[i];
    element.addEventListener("touchstart", doTouchStart);
    element.addEventListener("touchend", doTouchEnd);
}

function doTouchStart() {
    this.style.backgroundColor = "red";
}

function doTouchEnd() {
    window.location.href = this.getAttribute("data-url");
}