Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php foreach结果中循环javascript_Javascript_Php_Codeigniter_Loops - Fatal编程技术网

在php foreach结果中循环javascript

在php foreach结果中循环javascript,javascript,php,codeigniter,loops,Javascript,Php,Codeigniter,Loops,我想在我点击中的星星时,在每个评级的星星上都有一个反馈 以下是我目前的代码: 当我单击第一行时,它将显示该星星的标题。现在,当我单击第二行时,它不会显示该星星的标题 <table class="table table-striped table-hover"> <thead> <tr> <th>&nbsp;</th> <th>&nb

我想在我点击中的星星时,在每个评级的星星上都有一个反馈

以下是我目前的代码:

当我单击第一行时,它将显示该星星的标题。现在,当我单击第二行时,它不会显示该星星的标题

  <table class="table table-striped table-hover">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th>&nbsp;</th>
            <th>Feedback</th>
        </tr>
    </thead>

    <?php foreach($designation_show->result() as $r){?>
    <tr>
        <td>
            <inut type = "hidden" name = "template_id" id = "template" value=<?php echo $r->t_id;?> />
            <?php echo $r->question_description;?>
        </td>
        <td>
            <fieldset id='rate1' class="rating">
                <input class="stars" type="radio" id="star5" name="rating" value="5" />
                <label class = "full" for="star5" title="Outstanding - 5 stars"></label>
                <input class="stars" type="radio" id="star4" name="rating" value="4" />
                <label class = "full" for="star4" title="Exceeds Expectation - 4 stars"></label>
                <input class="stars" type="radio" id="star3" name="rating" value="3" />
                <label class = "full" for="star3" title="Meets Expectation - 3 stars"></label>
                <input class="stars" type="radio" id="star2" name="rating" value="2" />
                <label class = "full" for="star2" title="Improvement Needed - 2 stars"></label>
                <input class="stars" type="radio" id="star1" name="rating" value="1" />
                <label class = "full" for="star1" title="Failed - 1 star"></label> 
            </fieldset>
        </td>
        <td>
            <div id='feedback'></div>
        </td>             
    </tr>
    <script>
        $(document).ready(function () {

            $("#rate1 .stars").click(function () {

                var label = $("label[for='" + $(this).attr('id') + "']");

                    $("#feedback").text(label.attr('title'));
                    $(this).attr("checked"); 

            });

       });
    </script>
   <?php } ?>
</table>

反馈
/>
$(文档).ready(函数(){
$(“#rate1.stars”)。单击(函数(){
var label=$(“label[for='”+$(this.attr('id')+”]);
$(“#反馈”).text(label.attr('title');
$(此).attr(“已检查”);
});
});
  • 您需要将ID更改为唯一的
  • 不要循环脚本
  • 大概是这样的:

    $(函数(){
    $(.rating.stars”)。在(“单击”,函数(){
    var title=$(this.next().prop(“title”);
    $(此).tr.find(.feedback”).text(标题);
    });
    });
    
    
    反馈
    说明1
    说明2
    
    您的问题是什么?我想在单击时在其标签下显示星星的标题。但是发生了什么!什么事没有发生!你的实际问题是什么欢迎来到SO。请阅读,当我单击第一行时,它会显示该星星的标题。现在,当我点击第二行时,它没有显示那颗星的标题。有一些打字错误。再试一次