dongtanlin0765 2012-04-05 19:59
浏览 25
已采纳

如何在javascript中获取复选框批量值

i want to get all the details of youtube,so if the user tick the checkbox i want to get the full details of video in javascript,i have done but only i can get first word from the you tube name, you tube name,example $name="Geet - Episode 456 - Clip 1 [24th November 2011] HQ" so alert(name) is showing only Geet .why? i need full name. this is my code:where i have do the mistake.

     <?php

     $watch="youtubelink";
     $thumbnail="youyubeimage";
     $val="somevalue";
     $name="youtubename";
     //eg:$name="Geet - Episode 456 - Clip 1 [24th November 2011] *HQ*";
    $results=$watch.",".$thumbnail.",".$val.",".$name;
     ?>
      <input type="checkbox" name="checkbox[]" id="checkbox[]" class="addbtn" value=<?php echo $results;?>  />

this is my js:

   function chkbox()
      { 
      $('[name^=checkbox]:checked').each(function() { 
     var ckballvalue=($(this).val());   
     var fields = ckballvalue.split(/,/); 
     var link = fields[0];
     var thumbnail = fields[1];
     var name = fields[3];
     //var description = fields[4];
     var categ = fields[2]; 
    alert(name);
     var data = {
     action: 'my_action',
     link:link,
     thumbnail:thumbnail,
     name:name, 
     categ:categ

};
  • 写回答

1条回答 默认 最新

  • doudie2693 2012-04-05 20:11
    关注

    The html you are generating from PHP needs to have quoted attributes:

    value="<?php echo $results;?>"
    
    // which will end up as:
    value="Geet - Episode 456 - Clip 1 [24th November 2011] HQ"
    

    That is:

    <input type="checkbox" name="checkbox[]" id="checkbox[]" class="addbtn" value="<?php echo $results;?>" />
    

    Otherwise you have:

    value=Geet - Episode 456 - Clip 1 [24th November 2011] HQ
    

    So the value attribute only goes as far as the first space. (If you use "View Source" in the browser you'll see the difference.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法