用我的名字创建一个变量.然后提醒字符串“hello-from”加上我创建的变量

Create a variable with my name. Then alert the string “hello from” plus the variable I created

本文关键字:变量 创建 hello-from 字符串 然后 我的名字 一个      更新时间:2023-09-26

这是我到目前为止所拥有的,但我的var名称没有出现在警报中。请帮忙!我只需要将变量Name添加到当前警报中"。

HTML

<input type="button" onclick="show_alert()" value="Name" />

编写脚本

function show_alert(name) 
{
    var name= "Joshua";
    alert("Hello from"'+ name');    
} 

将警报更改为:

alert("Hello from" + name);

试试看,javascript变量没有封装在'

alert("Hello from "+ name);

而不是

 alert("Hello from"'+ name');

您的代码:

 function show_alert() 
  {     
    var name = document.getElementById('myname').value;
    alert("Hello from"+ name);
  } 

HTML:

<body>
     <input type="text" name="myname" id="myname" value="Joshua" />
   <input type="button" onclick="show_alert()" value="Name" />
 </body>

删除单引号`

alert("Hello from" + name);

DEMO