gpt4 book ai didi

javascript - HTML 在 UIWebView 中选择 标签下的一行

转载 作者:行者123 更新时间:2023-11-28 01:10:57 25 4
gpt4 key购买 nike

我有一个 UIWebView,其中加载了一个 htmlString,其中包含标签下表格格式的文本。标签位于标签内。在标签下。我需要做的是更改点击时文本的颜色。

代码:

<tr id = '1' valign=\"top\">
<td>
<p>
<a href = '#1'> TEXT </a>
</p>
</td>
<td>
<p>
<a href = '#1'> TRANSLATION </a>
</p>
</td>
</tr>

我需要的是,当点击“文本”或“翻译”时,文本颜色应该改变。

我正在编写这段 JavaScript 代码来改变颜色。

<script> var el = document.getElementById(\"%d\"); 
window.onload = function () {
window.scrollTo(20,el.offsetTop);
el.style.color=\"red\";
}
</script>

请帮忙。

更新:

这是我的 html 文件,我将上面给定的“tr”标记替换为 ###CONTENT###

<html>
<head>
<style type='text/css'>

a:link {
text-decoration : none;
color: black;
}

a:visited {
color: black;
}

a:hover {
color: red;
}


table {
table-layout: fixed;
width: 280px;
}
html,body {
margin: 0;padding: 0;
}
html {
display: table;
}
body {
font-family:'MSH-Quraan1';
font-size:17px;
display: table-cell;
vertical-align: middle;
padding: 10px;
text-align: center;-webkit-text-size-adjust: none;
}
</style>
</head>
<body>
<table>
###CONTENT###
</table>
</body>
</html>

最佳答案

为什么使用 JavaScript?

尝试像这样使用 CSS

tr #1:active{
color:red}

我不是 javascript 专家,但试试这个:

<script>

document.getElementById('1').onclick = changeColor;

function changeColor() {
document.body.style.color = "red";
return false;
}

</script>

关于javascript - HTML 在 UIWebView 中选择 <td> 标签下的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24448162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com