Javascript 韩元';使用HTMLDOM显示日期
我正在使用一个名为showDate()的JavaScript函数,该函数传递了一个参数(称为id)。我试图让函数显示带有innerHTML属性的日期,该属性在函数调用中传递给函数 这是我的密码:Javascript 韩元';使用HTMLDOM显示日期,javascript,dom,Javascript,Dom,我正在使用一个名为showDate()的JavaScript函数,该函数传递了一个参数(称为id)。我试图让函数显示带有innerHTML属性的日期,该属性在函数调用中传递给函数 这是我的密码: <!DOCTYPE html> <html> <head> <title>My bored html</title> <script type = "text/javascript"> function showDate(id) {
<!DOCTYPE html>
<html>
<head>
<title>My bored html</title>
<script type = "text/javascript">
function showDate(id)
{
document.getElementById(id).innerHTML = Date();
}
</script>
</head>
<p id = "Datepara" style = "font-family:comic sans ms;color:orange;text-align:center;font-size:25px;">
Date: 24/9/12 <br /><br /><br/>
</p>
<input type = "button" onclick = "showDate(Datepara)" value = "Display today's date" />
</body>
</html>
我无聊的html
函数showDate(id)
{
document.getElementById(id).innerHTML=Date();
}
日期:2012年9月24日
更改
showDate(Datepara)
借
否则,您将传递html元素,而不仅仅是id。更改
showDate(Datepara)
借
否则,您将传递html元素,而不仅仅是id。您需要在元素的id字符串周围加引号:
<!DOCTYPE html>
<html>
<head>
<title>My bored html</title>
<script type = "text/javascript">
function showDate(id)
{
document.getElementById(id).innerHTML = Date();
}
</script>
</head>
<p id = "Datepara" style = "font-family:comic sans ms;color:orange;text-align:center;font-size:25px;">
Date: 24/9/12 <br /><br /><br/>
</p>
<input type = "button" onclick = "showDate('Datepara')" value = "Display today's date" />
</body>
</html>
我无聊的html
函数showDate(id)
{
document.getElementById(id).innerHTML=Date();
}
日期:2012年9月24日
您需要在元素的id字符串周围加引号:
<!DOCTYPE html>
<html>
<head>
<title>My bored html</title>
<script type = "text/javascript">
function showDate(id)
{
document.getElementById(id).innerHTML = Date();
}
</script>
</head>
<p id = "Datepara" style = "font-family:comic sans ms;color:orange;text-align:center;font-size:25px;">
Date: 24/9/12 <br /><br /><br/>
</p>
<input type = "button" onclick = "showDate('Datepara')" value = "Display today's date" />
</body>
</html>
我无聊的html
函数showDate(id)
{
document.getElementById(id).innerHTML=Date();
}
日期:2012年9月24日
最好的方法是:
<input type = "button" onclick = "show Date('Datepara')" value = "Display today's date" />
我希望这会有所帮助。最好的方法是:
<input type = "button" onclick = "show Date('Datepara')" value = "Display today's date" />
我希望这会有帮助。该死!我知道这是件很琐碎的事,该死!我知道这是一件非常琐碎的事情,Firebug和Chrome的“Inspect Element”功能对我帮助很大。让2个人使用internet explorer>:(我在家使用Chrome Firebug和Chrome的“Inspect Element”功能对我帮助很大。让2个人使用internet explorer>:(我在家使用Chrome。)