为什么我不能使用php在HTML属性元素中打印id ?


why cant i print a id within a html attribute element using php

伙计们,我有一个问题,在php输出id。我要做的是创建一篇文章,当用户单击编辑按钮时,文本区域显示为编辑,而原始文章隐藏。我使用jquery和PHP来做。问题是,当用户单击编辑按钮时,隐藏文本区域没有显示,当我查看浏览器源时,我发现id没有在隐藏文本区域输出。所以,请指导我如何在隐藏区域打印id。下面是jquery的代码:

$(".hidden_text_edit").click(function(){
    var id=$(this).attr("id");

$(".hidden_edit_4_session").find("id").show();    
var hide_status=$(".statusboxes").attr('type');
var title=$(".title_s_2copy").attr('type');
var data=$(".data_s_2copy").attr('type');
$(hide_status).hide();
//tinyMCE.get('.hidden_edit_4_session').setContent(data);
$(".title_s_edit").val(title);
});
$(".close_edit").click(function(){
    $(".hidden_edit_4_session").hide();    
var hide_status=$(".statusboxes").attr('div', 'type');
$(hide_status).show();
});

文章和隐藏文本区域逻辑代码:

<?php
if(isset($_SESSION['app'])){
    $statusui="<div class='jumbotron'><input type='text' class='form-control title_s' name='status_title' placeholder='Title ' ><br>"
            . "<textarea id='wall_id_1' class='update_session' placeholder='whats up ".$session_uname."'>"
            . "</textarea>"
            . "<button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s'>Post</button></div>";
 $statusui_edit="<div id=".$updateid." class='hidden_edit_4_session".$updateid." jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' ><div>&nbsp;</div>"
            . "<textarea id='wall_edit_1' value='".html_entity_decode($data)."' class='session_edit' placeholder='whats up ".$session_uname."'>"
            . "" .html_entity_decode($data)."</textarea><br>"
            . "<button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div>";

}
 elseif ($is_friend==TRUE&&$session_uname!=$f_uname) {
       $statusui="<input type='text' class='form-control title_f' name='status_title' placeholder='Title'><br>"
               . "<textarea id='wall_id_1' type='c' value='".html_entity_decode($data)." class='status_4_expresspad_friend' style='' placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>"
               . "</textarea><br>"
               . "<button style='float:right;' class='btn btn-warning btn-large btn-lg post-f'>Post</button><br><br><br><div>&nbsp;</div>";
       $statusui_edit="<div class='hidden_edit_4_friend jumbotron'><a title='Close without editing' href='#' class='pull-right close_edit_f'>Close X</a><input type='text' class='form-control title_f_edit' name='status_title' value='".html_entity_decode($title)."' placeholder='Title'><br>"
               . "<textarea id='wall_edit_2' value='".html_entity_decode($data)."' class='update_4_expresspad'placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>"
               . "</textarea><br>"
               . "<button style='float:right;' type='c' class='btn btn-warning btn-large btn-lg post-f-edit'>Update</button>";
}
?>

下面是状态列表用隐藏文本区域的逻辑循环输出的代码:

<?php

$status2view=$project->statusView($session_uname, $f_uname);
//gives output on var dump
#row vars to extract user's update data.


    foreach($status2view as $row){
           $id=$row['update_id'];



$status_replies_=$project->reply2StatusView($id);


foreach ($status_replies_ as $row) {
                $status_reply_id=$row['update_id'];
                $reply_author=$row['author'];
                $reply_d=htmlentities($row['update_body']);
                $reply_data=  stripslashes($reply_d);
                $reply_t=  htmlentities($row['title']);
                $reply_title=  stripslashes($reply_t);
                $account_name=$row['account_name'];
               $reply_date=$row['time'];
               $reply_delete_button="";
               if ($reply_author==$session_uname || $account_name==$session_uname) {
                   $reply_delete_button="<li><span id='$status_reply_id' class='delete_reply_btn glyphicon glyphicon-remove'><a href='#' title='Delete this comment'>Remove X</a></span></li>";
               }
              $status_replies="<div id='".$status_reply_id."' class='replyboxes'><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a>".$reply_date ."<legend>"
                       . "<b class='caret'><button type='button' class='btn btn-danger dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true' ><span class='glyphicon glyphicon-edit'></span>
                        <ul class='dropdown-menu'>".$reply_delete_button." "
                      . "<li><a href='#' class='hidden_text_area glyphicon glyphicon-pencil' title='Edit this comment' >Edit</a></li>"
                      . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>"
                      . "</button></b></legend><br>".  html_entity_decode($reply_data)."";
            }
        }
     foreach ($status2view as $row1) {
         //got values here.
                $updateid=$row1['update_id'];
                $account_name=$row1['account_name'];
                $os_id=$row1['os_id'];
                $author=$row1['author'];
                $post_date=$row1['time'];
                $title= $row1['title'];
                $data= $row1['update_body'];
                $statusdeletebutton='';
                if ($author==$session_uname || $account_name==$session_uname) {
                $statusdeletebutton='<li>'
                           . '<a href="#" id="'.$updateid.'" class="delete_4_session hidden_text_delete_'.$updateid.' glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li>';
                }
                $status_list= '<div id="'.$updateid.'" type="'.$updateid.'" class="statusboxes jumbotron">'
                        . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left"><div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3>'
                        . '<span class="pull-right">'
                        . '<div class="dropdown">'
                        . '<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  >'
                        . '<span class="glyphicon glyphicon-edit"></span></button>'
                        . '<ul class="dropdown-menu">'
                        . '<li><a href="#" id="'.$updateid.'" type="'.$updateid.'" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'.$statusdeletebutton.'</ul></div></span><br><hr><span class="pull-left data_s_2copy" id="'.$updateid.'" value="'.html_entity_decode($data).'" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;">'
                        . html_entity_decode($data).'</span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u='.$author.'">'.$author.   '</a>   '.$post_date.'</small></b>'
                        . '<br>'.$status_replies.'<br>'.$statusui_edit;

                if ($is_friend==TRUE||$session_uname==$f_uname) {
                    $status_list.= '<textarea id="'.$updateid.'"  class="status_update input-custom2" placeholder="comment''s"></textarea>'
                            . '<button id="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div>';

                    }
                    echo $status_list;
                }

下面是浏览器页面的源代码:-

<div class='jumbotron'><input type='text' class='form-control title_s' name='status_title' placeholder='Title ' ><br><textarea id='wall_id_1' class='update_session' placeholder='whats up qwerty'></textarea><button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s'>Post</button></div><div id="7" type="7" class="statusboxes jumbotron"><h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left"><div id="7" class="title_s_2copy" value="hello shan!">hello shan!</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  ><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a href="#" id="7" type="7" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li><li><a href="#" id="7" class="delete_4_session hidden_text_delete_7 glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><span class="pull-left data_s_2copy" id="7" value="<p>what's up.</p>" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;"><p>what's up.</p></span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u=qwerty">qwerty</a>   2015-10-20 10:13:18</small></b><br><br><div id='' class='hidden_edit_4_session jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='' placeholder='Title' ><div>&nbsp;</div><textarea id='wall_edit_1' value='' class='session_edit' placeholder='whats up qwerty'></textarea><br><button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div><textarea id="7"  class="status_update input-custom2" placeholder="comment's"></textarea><button id="7" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div><div id="6" type="6" class="statusboxes jumbotron"><h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left"><div id="6" class="title_s_2copy" value="pen test">pen test</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  ><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a href="#" id="6" type="6" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li><li><a href="#" id="6" class="delete_4_session hidden_text_delete_6 glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><span class="pull-left data_s_2copy" id="6" value="<p>&lt;script type="text/javascript"&gt;alert("hooya hacked")&lt;/script&gt;</p>" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;"><p>&lt;script type="text/javascript"&gt;alert("hooya hacked")&lt;/script&gt;</p></span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u=qwerty">qwerty</a>   2015-10-18 21:53:31</small></b><br><br><div id='' class='hidden_edit_4_session jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='' placeholder='Title' ><div>&nbsp;</div><textarea id='wall_edit_1' value='' class='session_edit' placeholder='whats up qwerty'></textarea><br><button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div><textarea id="6"  class="status_update input-custom2" placeholder="comment's"></textarea><button id="6" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div><div id="5" type="5" class="statusboxes jumbotron"><h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left"><div id="5" class="title_s_2copy" value="pen test">pen test</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  ><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a href="#" id="5" type="5" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li><li><a href="#" id="5" class="delete_4_session hidden_text_delete_5 glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><span class="pull-left data_s_2copy" id="5" value="<p>&lt;script type="text/javascript"&gt;alert("hooya hacked")&lt;/script&gt;</p>" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;"><p>&lt;script type="text/javascript"&gt;alert("hooya hacked")&lt;/script&gt;</p></span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u=qwerty">qwerty</a>   2015-10-18 21:53:30</small></b><br><br><div id='' class='hidden_edit_4_session jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='' placeholder='Title' ><div>&nbsp;</div><textarea id='wall_edit_1' value='' class='session_edit' placeholder='whats up qwerty'></textarea><br><button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div><textarea id="5"  class="status_update input-custom2" placeholder="comment's"></textarea><button id="5" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div><div id="3" type="3" class="statusboxes jumbotron"><h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left"><div id="3" class="title_s_2copy" value="this is not working">this is not working</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  ><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a href="#" id="3" type="3" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li><li><a href="#" id="3" class="delete_4_session hidden_text_delete_3 glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><span class="pull-left data_s_2copy" id="3" value="<p>wht to do???</p>" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;"><p>wht to do???</p></span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u=qwerty">qwerty</a>   2015-10-17 19:32:35</small></b><br><br><div id='' class='hidden_edit_4_session jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='' placeholder='Title' ><div>&nbsp;</div><textarea id='wall_edit_1' value='' class='session_edit' placeholder='whats up qwerty'></textarea><br><button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div><textarea id="3"  class="status_update input-custom2" placeholder="comment's"></textarea><button id="3" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div><div id="2" type="2" class="statusboxes jumbotron"><h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left"><div id="2" class="title_s_2copy" value="im grateful to mother nature and god">im grateful to mother nature and god</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  ><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a href="#" id="2" type="2" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li><li><a href="#" id="2" class="delete_4_session hidden_text_delete_2 glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><span class="pull-left data_s_2copy" id="2" value="<p>as the title says im grateful</p>" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;"><p>as the title says im grateful</p></span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u=qwerty">qwerty</a>   2015-10-17 19:29:15</small></b><br><br><div id='' class='hidden_edit_4_session jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='' placeholder='Title' ><div>&nbsp;</div><textarea id='wall_edit_1' value='' class='session_edit' placeholder='whats up qwerty'></textarea><br><button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div><textarea id="2"  class="status_update input-custom2" placeholder="comment's"></textarea><button id="2" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div><div id="1" type="1" class="statusboxes jumbotron"><h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left"><div id="1" class="title_s_2copy" value="hello world">hello world</div></h3><span class="pull-right"><div class="dropdown"><button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  ><span class="glyphicon glyphicon-edit"></span></button><ul class="dropdown-menu"><li><a href="#" id="1" type="1" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li><li><a href="#" id="1" class="delete_4_session hidden_text_delete_1 glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li></ul></div></span><br><hr><span class="pull-left data_s_2copy" id="1" value="<p>this is my 1st post</p>" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;"><p>this is my 1st post</p></span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u=qwerty">qwerty</a>   2015-10-17 19:25:09</small></b><br><br><div id='' class='hidden_edit_4_session jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='' placeholder='Title' ><div>&nbsp;</div><textarea id='wall_edit_1' value='' class='session_edit' placeholder='whats up qwerty'></textarea><br><button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div><textarea id="1"  class="status_update input-custom2" placeholder="comment's"></textarea><button id="1" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div>    </div>

你的代码问题是与id命名,因为它们都是数字

对于HTML 4, ID和NAME标记必须以字母([a- za -z])开头,后面可以是任意数量的字母、数字([0-9])、连字符("-")、下划线("_")、冒号(":")和句点("。")。HTML 5更加宽松,只规定id必须包含至少一个字符,不能包含任何空格字符。

HTML中id属性的有效值是什么?