我正在合作一个气象卫星应用程序,在我的第一次尝试。我构建了一些非常简单的模板来满足我的需求。
在我的代码中,我不得不检查输入文本的值。所以我在那个文本框上设置了一个事件。
这是文本输入:
<input type="text" name="meName" id="mockupName" />
<input type="button" {{buttonDisabled}} id="mockupCreate" value="New Mockup" />事件检查文本值并禁用或启用按钮。直截了当。
这是一个事件:
'keydown #mockupName': function(e) {
if (e.target.value.trim() == '') {
Session.set('buttonDisabled','disabled');
} else {
Session.set('buttonDisabled','');
}
},一切都很顺利。
e.target对我的文本输入有一个引用,并且值存储它的值。
现在,我从另一个页面引用了这个模板,在我编写的一个大模板中:
{{#if mockupSelected}}
<input type="button" id="sw_product" value="switch to product view" />
{{> mockupEditor}}
{{else}}
Select product from the left
{{/if}}实际上,当mockupSelected返回true时,我的模板就会出现。
事件不再起作用了.
当事件触发(及其触发)时,我执行一个console.log(e.target)
在我得到:<input#mockupName>对我输入的引用之前。现在我得到了:Object { __impl4cf1e782hg__: <input#mockupName>, parentNode_: undefined, firstChild_: undefined, lastChild_: undefined, nextSibling_: undefined, previousSibling_: undefined, treeScope_: Object }
具有一系列属性的对象,其中一个包含我的引用。
以下是安装的流星软件包列表:
meteor-platform
natestrauser:cart
http
iron:router
accounts-base
accounts-password
accounts-ui
alanning:roles
aldeed:autoform
aldeed:collection2
twbs:bootstrap
jeremy:velocity-animate
ajduke:bootstrap-tokenfield
sergeyt:typeahead
standard-app-packages
babrahams:editable-text-wysiwyg-bootstrap-3
differential:vulcanize
dburles:collection-helpers
fortawesome:fontawesome
yogiben:admin我想知道如何访问该文本输入,因为我不知道那个键,而且getElementById正在返回相同的对象。
我可以迭代所有对象属性,并测试其中一个值是否实际上是文本类型的nodeElement,但我认为这不是一个解决方案。
有人能告诉我如何恢复正常的行为吗?
发布于 2015-02-23 23:05:33
我猜你试过了吗:
.html
<input type="text" name="meName" id="mockupName" class="mockupName" />
<input type="button" {{buttonDisabled}} id="mockupCreate" value="New Mockup" />.js
'keydown .mockupName': function(e) {
if (e.target.value.trim() == '') {
Session.set('buttonDisabled','disabled');
} else {
Session.set('buttonDisabled','');
}
},或者尝试更改控件的名称(mockupname -> uniqueMockupName)。我有一次有奇怪的行为时,有重复的字段名。
https://stackoverflow.com/questions/28683612
复制相似问题