当我点击输入你的名字时,div标签中不会弹出任何内容。我的目标是尝试使名称出现在具有不同id的所有span标签中。但它甚至不会出现在一个。我也在使用纯JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="DreStone.css">
<title> o </title>
<style>
</style>
<!-- JAVASCRIPT -->
<script src="util.js"></script>
<script>
/**********************
LOCAL NAMESPACE OBJECT
***********************/
var z={};
/**********************
EVENT HANDLERS
***********************/
z.showName = function()
{ var age = u.eid("names").value,
u.eid("firstname").innerHTML = "" + age;
}
/**********************
WINDOW.ONLOAD
***********************/
window.onload = function()
{
u.eid("nameinput").addEventListener('click', z.showName);
}
</script>
</head>
<body>
Please enter your name: <input id="names" type="text">
<button id="nameinput" type="button">Click after you enter your name</button>
<p>
How is your day going <span id="firstnam"> </span>
</p>
<div> I would like to you to take a look at this payment plan <span id="secondname"> </span>.
It may prove to be very valueable to you. If you do not care then ignore this. Thank you <span id="thirdname"> </span>
</div>
<div id="firstname">
</div>
</body>
</html>
任何帮助都会非常有用。感谢
答案 0 :(得分:0)
如何将其更改为替换功能?类似的东西:
document.body.innerHTML = document.body.innerHTML.replace("How is your day going", "How is your day going " + document.form[0].user.value] + "?");
答案 1 :(得分:0)
假设 u.eid()在util.js中并且有效,你有(,)instaed of(;)
AlertDialog
答案 2 :(得分:0)
试试这个:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> o </title>
<style>
</style>
<script>
/**********************
LOCAL NAMESPACE OBJECT
***********************/
var z={};
/**********************
EVENT HANDLERS
***********************/
z.showName = function()
{ var age = document.getElementById("names").value;
document.getElementById("firstname").innerHTML = "" + age;
}
/**********************
WINDOW.ONLOAD
***********************/
window.onload = function()
{
document.getElementById("nameinput").addEventListener('click', z.showName);
}
</script>
</head>
<body>
Please enter your name: <input id="names" type="text">
<button id="nameinput" type="button">Click after you enter your name</button>
<p>
How is your day going <span id="firstnam"> </span>
</p>
<div> I would like to you to take a look at this payment plan <span id="secondname"> </span>.
It may prove to be very valueable to you. If you do not care then ignore this. Thank you <span id="thirdname"> </span>
</div>
<div id="firstname">
</div>
</body>
</html>
这对我有用