首页 \ 问答 \ JavaScript初学者:为什么这不起作用?(JavaScript beginner: why does this not work?)

JavaScript初学者:为什么这不起作用?(JavaScript beginner: why does this not work?)

我的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

我很确定它的排序和我的语法我需要继续工作,非常感谢任何建议,谢谢!


My html page is not responding to this code I wrote in JS, i'm a total beginner, and just started learning JS, can somebody tell me why this doesn't work?

/* 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

I'm pretty sure it's ordering and my syntax i need to work on, any advice is greatly appreciated thank you!


原文:https://stackoverflow.com/questions/44790585
更新时间:2021-04-27 11:04

最满意答案

您应该为CartViewModel所有CartItemViewModel实例处理PropertyChanged事件。 您收到PropertyChangedEventArgs ,其中有一个名为PropertyName的成员。 当它的值为“ Raispropertychanged(TotalValue) ”时,您可以调用Raispropertychanged(TotalValue) 。 代码完全添加到CartViewModel


You should handle the PropertyChanged event for all the instances of CartItemViewModel inside the CartViewModel. You receive PropertyChangedEventArgs which has a member called PropertyName. When its value is "SubTotal" then you can call Raispropertychanged(TotalValue). The code is completely added to CartViewModel.

相关问答

更多
  • 第一个版本只是减少了创建的对象数量,因为无论访问命令属性多少次,都只存在一个实例。 在大多数情况下,这可能没有那么大的差别。 大多数人使用代码片段来生成代码,因此生成正确的代码不是任何额外的输入。 The first version simply reduces the number of objects created, since only one instance would exist no matter how many times the command property is accessed ...
  • 我发现问题=>显然MvxCachingFragmentCompatActivity由于某种原因不喜欢MvxCachingFragmentCompatActivity 。 第一个样品(工作) 在第一个示例中,我直接在从MvxCachingFragmentCompatActivity扩展的MainViewModel上执行RegisterAppStart<> 。 这是完美的 一些代码示例( 完整代码请参阅链接 ) public class App : MvvmCross.Core.ViewModels.MvxAp ...
  • 正如我们在OP的评论中所做的那样,交换机的事件被联系起来了。 因此,绑定没有做任何事情。 解决此问题的最简单方法是将以下代码添加到LinkerPleaseInclude.cs文件中,MvvmCross在Startup NuGet中提供该文件,并通过可用于Visual Studio和Xamarin Studio的模板: public void Include(UISwitch sw) { sw.On = !sw.On; sw.ValueChanged += (sender, args) = ...
  • 更新Quantity属性时忘记调用RaiseCanExecuteChanged 。 另外,您不需要设置始终返回true的CanExecute : public class CartItemViewModel : MvxNotifyPropertyChanged { private int quantity = 0; public CartItemViewModel() { IncreaseCommand = new MvxCommand(Ex ...
  • 您应该为CartViewModel所有CartItemViewModel实例处理PropertyChanged事件。 您收到PropertyChangedEventArgs ,其中有一个名为PropertyName的成员。 当它的值为“ Raispropertychanged(TotalValue) ”时,您可以调用Raispropertychanged(TotalValue) 。 代码完全添加到CartViewModel 。 You should handle the PropertyChanged ev ...
  • Mvx.MvxBindableListView是一个旧名称,在MvvmCross v.3中,这个控件叫做Mvx.MvxListView https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Binding.Droid/Views/MvxListView.cs Mvx.MvxBindableListView is an old name, in MvvmCross v.3 this control is cal ...
  • 从tracem看,它看起来像是一个直截了当的错误,可能是在解决另一个问题时出现在某处的回归。 你最好的选择是在GitHub上为此打开一个问题 - https://github.com/slodge/MvvmCross/issues/new ? 或者你可以将源代码分解并将其修复到你的分支中。 在此期间,也许尝试使用MvxListView? 或者创建一个新的可绑定ViewGroup? From the tracem it looks like a straight-forward bug, probably a ...
  • 该跟踪由MvxSidebarViewController中的MvxSidebarViewController代码触发。 protected virtual void SetupSideMenu() { var leftSideMenu = ResolveSideMenu(MvxPanelEnum.Left); var rightSideMenu = ResolveSideMenu(MvxPanelEnum.Right); if (leftSi ...
  • 我相信LegacyBar已经与MvvmCross一起使用 - 所以这肯定是你的选择。 或者,另一个可用选项是为Sherlock中的活动和/或片段添加数据绑定支持。 对于活动,MvvmCross使用几个小的代码层将活动调整为数据绑定: 生活场所 数据绑定上下文 这个代码在MVVMCross for android中描述- 如何在代码中进行绑定? 如果您按照该问题中“附加”部分中的两个步骤操作,那么应该可以创建MvxSherlockActivity 对于片段,这里没有详细的现有答案,但这个过程基本上是相同的两个 ...
  • 您可以调整任何ViewController基类,以允许通过从中继承来提供MvvmCross数据绑定扩展。 例如,看看UIViewController本身如何在2层继承中进行调整: https://github.com/MvvmCross/MvvmCross/blob/v3.1/CrossCore/Cirrious.CrossCore.Touch/Views/MvxEventSourceViewController.cs https://github.com/MvvmCross/MvvmCross/blob/ ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)