我試圖實現一個動態幫助字段,當焦點隨着流星自動套用格式更改時發生更改(類似於您提問時出現在右側的「類似問題」框這裏)。但是當字段變得焦點時,我得到「ReferenceError:myFunc沒有定義」。帶onfocus的流星afQuickField找不到函數
我已經嘗試在我的.js文件中定義myFunc作爲非包裝函數和模板助手,並在.html文件中作爲<script>
包裝函數,甚至作爲onfocus的一部分內嵌函數(這真的很難看,因爲它無法找到.js文件中的標題和文本數組),但仍然得到ReferenceError。與onclick相同的問題。我也嘗試了一個模板焦點或點擊事件(這個從不會觸發)
下面的示例代碼。爲了清楚起見,我忽略了所有的<div>s
,但表單在實際代碼中正確顯示,它只是onfocus屬性不起作用。
的.html
<template name="updateProfileForm">
{{#autoForm id="updateProfileForm" collection="Meteor.users" doc=currentUser type="update"}}
{{> afQuickField
name="emails.1.address"
id="secondaryEmail"
label='Secondary Email'
onfocus='ProfileUpdateHelp("secondary")'}}
</template>
的.js
Template.updateProfileForm.helpers ({
ProfileUpdateHelp: function(fieldName) {
// console.log("This:", this);
// console.log("instance():", instance());
TemplateVar.set('helpTitle', profileUpdateHelpTitles[fieldName]);
TemplateVar.set('helpText', profileUpdateHelpTexts[fieldName]);
},
});
profileUpdateHelpTitles = {
primary: "Primary email address",
secondary: "Secondary email address",
};
profileUpdateHelpTexts = {
primary: "Primary email address help",
secondary: "Secondary email address help",
};
我也試圖與事件和他們沒有火(我希望所有的3至火):
Template.updateProfileForm.events({
"click #secondaryEmail": function(e) {
alert("Click");
},
"focus #secondaryEmail": function(e) {
alert("focus");
},
"blur #secondaryEmail": function(e) {
alert("blur");
},
});
請嘗試事件而不是幫手。 –
Template.updateProfileForm.events({blur} #secondaryEmail':function(events){/ *做任何你想做的事情* /} }) –
事件永遠不會觸發。請參閱上面的編輯帖子。 –