dongwen9975 2014-12-15 09:12
浏览 29
已采纳

在for循环中检查无线电输入(仅包含值的那些)

this is my code:

<?php 

if(!empty($wpjobus_resume_skills)) {

for ($i = 0; $i < (count($wpjobus_resume_skills)); $i++) {

?>

    <div style="text-align: center;">
       <span>20%</span>
       <input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='20%' class='slider_value'>
    </div>


    <div style="text-align: center;">
        <span>40%</span>
        <input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='40%' class='slider_value'>
    </div>

    <div style="text-align: center;">
        <span>60%</span>                                    
        <input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='60%' class='slider_value'>
    </div>

    <div style="text-align: center;">
        <span>80%</span>
        <input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='80%' class='slider_value'>
    </div>

    <div style="text-align: center;">
        <span>100%</span>
        <input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='100%' class='slider_value'>                          
    </div>

ok. I am storing my data in a post meta var wpjobus_resume_skills. I want to only checked the inputs which contains a value. for example on 1st iteration of the for loop, the input with 80% value should be checked as i have 80% in my var $wpjobus_resume_skills[$i][1]. In the second loop lets say 40% is saved then i want to only checked that 40% input.

screenshot: should be like this

enter image description here

this is what i am trying which checked all the values:

<?php
if( !empty($wpjobus_resume_skills[$i][1]) )
{
    <script type="text/javascript">
        jQuery('.checkedClass<?php echo $i; ?>').prop('checked', true);
    </script>
}

any help would be appreciated.

my array: print_r($wpjobus_resume_skills);

Array
(
    [0] => Array
        (
            [0] => C++
            [1] => 40%
        )

    [1] => Array
        (
            [0] => Java
            [1] => 60%
        )

    [2] => Array
        (
            [0] => Rails
            [1] => 80%
        )

    [3] => Array
        (
            [0] => HTML 5
            [1] => 100%
        )

    [4] => Array
        (
            [0] => Android
            [1] => 20%
        )

)

This worked for me:

adding this to the input tag <?php echo ($wpjobus_resume_skills[$i][1]=='100%')?'checked':'';?>

<input style="width:50%; float: none" type='checkbox' class="checkingtheclass checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' <?php echo ($wpjobus_resume_skills[$i][1]=='100%')?'checked':'';?> value='100%' class='slider_value'>
  • 写回答

2条回答 默认 最新

  • dongtuo3370 2014-12-15 09:29
    关注

    Do it with PHP code.

    Inside your loop add this check in each tag.

       <?php echo ($wpjobus_resume_skills[$i][1]=='YOUR_VALUE')?'checked':'';?>
    

    For example

    <?php
    for ($i = 0; $i < (count($wpjobus_resume_skills)); $i++) {
    ?>
    <input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo 
       $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' 
      name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='80%' 
     class='slider_value'      <?php echo ($wpjobus_resume_skills[$i][1]=='80%')?'checked':'';?>
    
     >
     .
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求