Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

javascript - Why is my code not working?

I just wrote this code and when I tested it, the javascript wouldn't work. I have javascript enabled and I tried with a different code and it worked. I think there's maybe a bug but I can't see it.

<!DOCTYPE html>
<html>
<body>
    <p id=“id”>Some Text</p>
    <script>
        document.getElementById(“id”).innerHTML=“Different Text”;
    </script>
</body>
</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are using smart quotes (“”) instead of normal quotes (""). Replace the quotes and it will work.

<p id="id">Some Text</p>
<script>
    document.getElementById("id").innerHTML="Different Text";
</script>

Perhaps this is because you are using a word processor, not an IDE?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...