最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Declare variable in the beginning of a html document - Stack Overflow

programmeradmin5浏览0评论

In PHP we can declare variables in the beginning of the document this way:

<?php
$title="Title of the webpage";
?>

In the html code this title will replace the echo $title in the html code of the webpage. Is it possible to do it using html and Javascript, I mean without using PHP?

In PHP we can declare variables in the beginning of the document this way:

<?php
$title="Title of the webpage";
?>

In the html code this title will replace the echo $title in the html code of the webpage. Is it possible to do it using html and Javascript, I mean without using PHP?

Share Improve this question edited Jul 17, 2012 at 19:20 j08691 208k32 gold badges269 silver badges280 bronze badges asked Jul 17, 2012 at 19:17 Nizar BarkallahNizar Barkallah 1091 gold badge5 silver badges11 bronze badges 3
  • howtocreate.co.uk/tutorials/javascript/variables – My Head Hurts Commented Jul 17, 2012 at 19:20
  • developer.mozilla/en/DOM/document.title – jbabey Commented Jul 17, 2012 at 19:21
  • The title is incorrect as it implies a document can have variables. It's actually the script within a page that can have variables. – Lee Taylor Commented Jul 17, 2012 at 20:00
Add a ment  | 

1 Answer 1

Reset to default 4
<script>
var someVariable="someValue";
document.title = someVariable;
</script>
发布评论

评论列表(0)

  1. 暂无评论