我在meteor框架内使用了一个复选框。无论我检查它还是取消选中它,它总是返回真值。我已经在网上尝试了很多选项。
代码如下: -
以下是表格的代码: -
<template name="subscribedKeyword">
<div class="issue" >
<div class="issue-content">
<h3>
{{category}}
<input id='pp' class="checktype" name="mark" type="checkbox" value="1" {{{done}}} />Get Notifications
<input type="hidden" name="mark" value="0" />
</h3>
</div>
</div>
</template>
以下是.js文件的代码
$('input[type="checkbox"]').on('change', function(e){
if($(this).prop('checked'))
{
$(this).next().val(1);
alert('$(this).next().val(1); '+$(this).next().val(1));
// Adding the loggedin user to the collection on checking the checkbox
Subscribed.update(id, {$addToSet: {categorySubscribedUsers : Meteor.user()}});
alert('value added to the subscribed collection');
var msg = "Hello "+ managerName +",\n\n"+ userName";
var subOfSubscribedDomain = 'Notification of Subscribed Domain';
//Send mail to Manager
alert('mail to mgr regarding subscription by user of domain');
Meteor.call('sendEmail',
managerEmailId,
senderEmail,
msg,
id,
subOfSubscribedDomain);
}
else
{
$(this).next().val(0);
alert('pulling of data from subscribed collection');
var subscribedPersons = Subscribed.findOne({category: issueManagerCategory}).categorySubscribedUsers;
if(subscribedPersons && subscribedPersons.length)
{
var j;
for(j= 0;j< subscribedPersons.length;j++)
{
if(subscribedPersons[j].username === Meteor.user().username)
{
var personId=subscribedPersons[j]._id;
Subscribed.update(id,{$pull:{categorySubscribedUsers:{_id:personId}}});
var msg = "Hello "+ managerName
var subOfUnSubscribedDomain = 'Notification of UnSubscribed Domain';
// Send mail to manager
Meteor.call('sendEmail',
managerEmailId,
senderEmail,
msg,
id,
subOfUnSubscribedDomain);
break;
}
}
}
}
});
我试过了: -
一切皆有可能。但仍然无能为力,任何指针要做什么??```
答案 0 :(得分:0)
试试这个..
if(document.getElementById('checkbox1').checked==true)
{
}
答案 1 :(得分:0)
那是因为你有这个开头的引号:
var msg = "Hello "+ managerName +",\n\n"+ userName";
^
从"
到最后});
的所有内容都被视为字符串,而您的JavaScript正在抛出:
Uncaught SyntaxError: Unexpected token ILLEGAL