复选框总是返回真值,而与复选框的状态无关

Checkbox always return true value irrespective of status of checkbox

本文关键字:复选框 状态 返回      更新时间:2023-09-26

我在of meter框架中使用了一个复选框。无论我是选中它还是取消选中它,它总是返回真值。我已经在网上尝试了很多选项。

代码如下:-

以下是表单的代码:-

<template name="subscribedKeyword"> 
    <div class="issue" > 
        <div class="issue-content">
            <h3>
                {{category}} 
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <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; 
            }
            }
         }
      }
});

我试过:-

  • document.getElementById()
  • $(").is(":已选中")

一切可能。但仍然一无所知,有指针该怎么办

试试这个。。

if(document.getElementById('checkbox1').checked==true)
{
}

这是因为你有这个开场引号:

var msg = "Hello "+ managerName +",'n'n"+ userName";
                                                  ^

"一直到最后的});的所有内容都被视为字符串,您的JavaScript正在抛出:

Uncaught SyntaxError: Unexpected token ILLEGAL