- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 html 页面没有响应我用 JS 编写的这段代码,我是一个初学者,刚开始学习 JS,有人能告诉我为什么这不起作用吗?
/* this is a practice file that'll play with js
nothing strange to look at here folks! */
var firstName = 'Steven';
var lastName = 'Curry';
var fullName = firstName + ' ' + lastName;
function Hotel(HotelName){
this.HotelName = HotelName;
this.numRooms = 20;
this.numGuests;
this.checkAvailability {
if(numRooms != 20 ){
return true;
}
else{
return false;
}
}
this.getHotelName = function(){
//can it work with this dot operator?
return this.HotelName;
}
}
var HiltonHotel = new Hotel('Hilton');
var hName = document.getElementById('hotelName');
hName.textContent = getHotelName();
var el = document.getElementById('name');
el.textContent = fullName;
<!DOCTYPE html>
<html>
<body>
<div id = 'greeting'> Hello
<span id="name">friend</span>!
<h1>Welcome To the <span id = 'hotelName'>Hyatt</span>
</div>
<script
src = "https://stacksnippets.net/js">
</script>
</body>
</html
我很确定它是有序的,我的语法需要改进,非常感谢任何建议,谢谢!
最佳答案
一些误解:
checkAvailability
是一个函数,您缺少括号。getHotelName
函数时,您必须引用 HiltonHotel
变量,才能访问和调用该函数。html
代码中存在一些小错误,在代码片段 中运行时,您不必添加单独的脚本,默认情况下它是连接在一起的。var firstName = 'Steven';
var lastName = 'Curry';
var fullName = firstName + ' ' + lastName;
function Hotel(HotelName) {
this.HotelName = HotelName;
this.numRooms = 20;
this.numGuests;
this.checkAvailability = function() { // it's a function (missing parens)
if (numRooms != 20) {
return true;
} else {
return false;
}
}
this.getHotelName = function() {
return this.HotelName;
}
}
var WeiHotel = new Hotel('Hilton');
var hName = document.getElementById('hotelName');
hName.textContent = WeiHotel.getHotelName(); // refer to the `WeiHotel` variable
var el = document.getElementById('name');
el.textContent = fullName;
<div id='greeting'> Hello
<span id="name">friend</span>!
<h1>Welcome To the <span id='hotelName'>Hyatt</span></h1>
</div>
关于JavaScript 初学者 : why does this not work?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44790585/
我不明白为什么我会从 GHCi 得到以下回复。不是Maybe构造函数? Prelude> :t Maybe :1:1: Not in scope: data constructor `Maybe' P
场景是我在此网站上有不同的访问级别,我有一个适用于所有有效用户的简单登录流程,但是我现在尝试分隔不同的用户以实现对页面的不同访问。 这是我页面开头的代码: // CHECKS IF THE USER
我的任务是:写下数字1-100。如果该数字可以被 3 整除,则将其写入数字“它可以被 3 整除”旁边的控制台。如果数字是 5,也将其写入数字旁边的控制台“它可以被 5 整除”,如果它不能被 3 整除,
我有一堆实现协议(protocol) P 的记录 (A B C)。 我想编写一个方法,该方法将选择一种记录类型,构造它,然后调用它的方法。 例如,如果我有一个记录列表(def types '(A B
我的任务是编写一个程序,根据以下三个因素来预测您的年度燃料使用量汽车加油。我必须使用两个单独的类。这是我的第一个类,名为 AnnualFuelUse。 public class AnnualFuelU
我是 JavaScript 新手。我已经通过 Learning JavaScript (o'reilly) 完成了我的工作,但我只是想制作我的第一个 JavaScript。 我认为最好从事我感兴趣的事
我真的刚刚开始学习如何用 Python 编写代码。我有兴趣 如何重现 u[x,t] 矩阵。我尝试了 return u,它抛出了一个错误。 如果此代码中 for 循环的位置正确并正常运行。 最重要的是,
我不明白 view("") 在作为 Model 对象一部分的以下 javascript 方法中的作用: addView: function(view) { this.views
所以我正在尝试将 AppKit 导入到我的 python 项目中。我正在使用 pyCharm,但每次我尝试导入时,都会收到以下错误消息: You are using pip version 6.0.8
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 2 年前。 Improve
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
好吧,不知道在哪里问这个,但我是一个初学者程序员,使用 Perl。我需要创建一个数组数组,但我不确定使用数组/哈希引用、哈希数组或数组哈希等是否更好。 我需要一组匹配项:@totalmatches 每
我最近开始学习 PHP。我做了一个基本的网站,基本上想给它密码。如果有人能告诉我为什么这不起作用,我将不胜感激。我知道它不起作用,因为我已经尝试过了;我只是不明白为什么。 ... REST OF W
我试图理解 C 中的整个指针和取消引用。我几乎明白了,但遇到了非常简单的代码,结果我不明白: char *ptr = "Characters"; char val = *ptr; char *chrp
首先,我有这个列表(在练习中建议): Members = [('Tessa','G1'),('Evan','G2'),('Tom','G3'), ('Mia','G3'),('Claire','G3'
我有以下列表: listofanimals = ['Dog', 'Cat', 'Frog', 'Tiger', 'Sheep', 'Lion'] 我想根据字典对这个列表进行排序: score_card
1 userID = floatval($userID); 13 } else { 14 $this->userID = floatval(
我是 R 新手,遇到了一段我不理解的代码。更具体地说,我想知道 .Internal做。这是我尝试转换为 Matlab 的示例: dunif 我想知道.Internal和 做。 非常感谢您, 西蒙 最
我是一名优秀的程序员,十分优秀!