【问题标题】:php & js - add emails to input textphp & js - 添加电子邮件以输入文本
【发布时间】:2015-04-08 20:34:36
【问题描述】:

我正在尝试将从 php if 条件生成的每个成员电子邮件发送到输入文本。选择效果很好,但是,我遇到的问题是找到一种方法,如果选择了多个复选框,则电子邮件总和将它们间隔为逗号。 现在我所拥有的是,如果我选中多个复选框,最后选择的电子邮件将替换旧的。 知道我该怎么做吗?此外,如果只选择了一封电子邮件,则无需添加逗号,如果未选中该复选框,则删除该电子邮件。

<?php if ( bp_has_members( "search_terms={$_POST['category']}")) : ?>
    <?php while ( bp_members() ) : bp_the_member(); ?>

           <table border="1" >          
            <tr>
             <td style="width:30px;">
              <input class="select_email" type="checkbox" name="get_email" value="<?php bp_member_user_email('type=user_email') ?>"/>
             </td>
             <td>
              <?php bp_member_user_email('type=user_email') ?>
             </td>
            </tr>
            </table>

    <?php endwhile; ?>
    <?php endif; ?>

jQuery

$(document).ready(function(){
    $(".select_email").click(function(){
       var select_check = $(this);
       var select_email = $(this).parent().find(".select_email").val();
       //var sum_email = select_email + ", " + select_email;
       if ( select_check.is(':checked') ) {
            // Do stuff
            alert(select_email + "   added");
            $("#my_email_to_id").val(sum_email);    
        }else {
            alert(select_email + "   removed");
        }
    });
});

【问题讨论】:

  • 我认为您输入的名称会阻止您实现您想要的我让您查看here以获取更多信息
  • 感谢 Jordan.. 不知道如何用 foreach 做到这一点.. 我试图在 js 中实现这一点

标签: javascript php jquery email checkbox


【解决方案1】:
<?php if ( bp_has_members( "search_terms={$_POST['category']}")) : ?>
    <?php while ( bp_members() ) : bp_the_member(); ?>

           <table border="1" >          
            <tr>
             <td style="width:30px;">
              <input class="select_email" type="checkbox" name="get_email[]" value="<?php bp_member_user_email('type=user_email') ?>"/>
             </td>
             <td>
              <?php bp_member_user_email('type=user_email') ?>
             </td>
            </tr>
            </table>

    <?php endwhile; ?>
    <?php endif; ?>

Jquery
$(document).ready(function(){
    $(".select_email").click(function(){
       var val = $(':checkbox:checked').map(function(){ return this.value; }).toArray().join(', ');
          alert(val);
          $("#my_email_to_id").val(sum_email);
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-14
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    相关资源
    最近更新 更多