在网页上列出电子邮件地址

时间:2019-01-24 14:47:10

标签: javascript html css

我正在尝试通过CSS着色和更改字体大小,但是它不起作用。下面是我写的,但是没有用,我不知道问题出在哪里。有什么想法会受到欢迎吗?

javascript

<script>
emailA = 'thestation.com'
emailA = ('jason' + '@' + emailA)
document.write('<a href="mailto:' + emailA +'">' + emailA +'</a>')
</script>
<br>

<script>
emailB = 'thestation.com'
emailB = ('arnold' + '@' + emailB)
document.write('<a href="mailto:' + emailB +'">' + emailB +'</a>')
</script>
<br>

<script>
emailC = 'thestation.com'
emailC = ('vincent' + '@' + emailC)
document.write('<a href="mailto:' + emailC +'">' + emailC +'</a>')
</script>
<br>

<script>
emailD = 'thestation.com'
emailD = ('paul' + '@' + emailD)
document.write('<a href="mailto:' + emailD +'">' + emailD +'</a>')
</script>

CSS

.emailA {
font-size: 2em;
color: green;
}
.emailB {
font-size: 3em;
colour: green;
}
.emailC {
font-size: 4em;
colour: green;
}
.emailD {
font-size: 5em;
colour: green;
}

HTML

<div class="emailA"></div>
<div class="emailB"></div>
<div class="emailC"></div>
<div class="emailD"></div>

2 个答案:

答案 0 :(得分:1)

您根本没有在HTML中使用div。尝试像这样在每个元素中添加类

document.write('<a href="mailto:' + emailA +'" class="emailA">' + emailA +'</a>')

,您将看到链接的样式正确。

答案 1 :(得分:0)

css表示法应该是颜色,而不是颜色。 一种格式化ist以在标签内使用class属性的方法,请参阅emailA。 要将锚放置在div中,必须重写CSS以影响锚(.emailB a)。 为了避免在将锚点注入唯一ID内时处理不同的div可能会有所帮助(emailC)。 在div中注入锚点时,必须在div呈现后执行注入代码(emailB,emailC)。

<!DOCTYPE html>
<html>
<head>
    <title>Color email address</title>
    <meta charset="UTF-8">
    <style type="text/css">
        .emailA {
            font-size: 2em;
            color: green;
        }
        .emailB a {
            font-size: 3em;
            color: red;
        }
        .emailC a {
            font-size: 4em;
            color: magenta;
        }
    </style>
</head>
<body>
    <script>
        emailA = 'thestation.com'
        emailA = ('jason' + '@' + emailA)
        document.write('<a class="emailA" href="mailto:' + emailA + '">' + emailA + '</a>')
    </script>
    <div class="emailB"></div>
    <script>
        emailB = 'thestation.com'
        emailB = ('arnold' + '@' + emailB)
        document.getElementsByClassName("emailB").item(0).innerHTML = '<a href="mailto:' + emailB + '">' + emailB + '</a>'
    </script>
    <div class="emailC" id="emailCId"></div>
    <script>
        emailC = 'thestation.com'
        emailC = ('vincent' + '@' + emailC)
        document.getElementById("emailCId").innerHTML = '<a href="mailto:' + emailC + '">' + emailC + '</a>'
    </script>
</body>
</html>