如何使用javascript将复选框数据传递给Textarea

时间:2012-07-05 08:25:40

标签: php javascript

这是我的javascriptcode

function AddContactPhoneNo()

{ 

    $("input[name='contact_id[]']:checked").each(function(){

        var opt_value = $(this).parent().parent().children('.contacts_firstname_01_contacts').text();
        var opt = "<option value='" + opt_value + "'>" + opt_value + "</option>";
        if  (opt_value != "")
        {
             alert(opt_value);
        }
    });}

这是我的HTML代码

<div class="contacts_headings_01">
                                        <div class="contacts_checkbox_01"><input name="contact_id[]" id="contact_id" type="checkbox"  value="'.$contacts_row['contact_id'].'" style="margin-top:0px ; margin-left:-3px;" /></div>
                                        <div class="contacts_firstname_01_contacts">'.$firstname.'</div>
                                        <div class="contacts_firstname_01">'.$lastname.'</div>
                                        <div class="contacts_firstname_01">'.$company.'</div>
                                        <div class="contacts_group_01_contacts_page">'.$groups1.'</div>
                                        <div class="contacts_firstname_01_contactdateofbirth">'.$birth_date.'</div>
                                        <div class="contacts_gender_01">'.$gender2.'</div>
                                        <div class="ncontacts_mobile_nmbr_01">'.$phone1.'</div>
                                    </div>

我有像这样的错误

$ is not defined

$("input[name='contact_id[]']:checked").each(function(){

2 个答案:

答案 0 :(得分:3)

这可能会发生jQuery未包含在内,或者您从不存在jQuery的CDN中包含它。

可能发生的另一种情况是在Wordpress中,你应该使用安全的jQuery。

您应该使用 jQuery('selector')而不是 $('selector')

PS:如果你在一个单独的JS文件中使用这部分代码,那么你应该在你的文档上包含所有脚本之上的jQuery。

答案 1 :(得分:1)

请添加jquery库,然后将解决此错误。

缺少Jquery Library。

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

只需在标题部分添加上述代码即可。

相关问题