0
상태 ID에 따라 숨기기 또는 표시 단추를 토글해야합니다. 상태가 활성 = 1이면 삭제 버튼 만 표시됩니다. status가 inactive = 0이면 다시 활성화 된 버튼 만 표시합니다. 그러나 활성 또는 비활성 상태가 표시되면 해당 데이터도 테이블에서 가져와야합니다. 이 새로운 질문에 대한 배경은 https://stackoverflow.com/questions/26187896/codeigniter-two-conditions-with-same-variable-breaking-statement 입니다. 이전 질문에서 나는 PHP를 사용하여 나의 문제를 해결하고 싶었다. 이제 Jquery를 사용하여 더 간단하게 만들었습니다. 그러나 숨기기 및 표시 단추를 토글하는 기능을 설정하는 데 문제가 있습니다.상태가 활성 또는 비활성 인 경우 데이터 키로
나는 올바른 것으로 생각하는 마크 업에 내 데이터를 이미 설정했습니다.
필요한 결과를 얻으려면이 기능을 어떻게 설정해야합니까?
<div class="container-d" style="padding-left:0;">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3 section-header buffer-bottom-md">
<h1>Users</h1>
</div>
</div>
<?php
/*start a1 : show delete message on success*/
if($this->session->flashdata('ses_user_deleted'))
{
?>
<div class="row">
<div class="col-md-12">
<?php echo $this->session->flashdata('ses_user_deleted');?>
</div>
</div>
<?php
}
/*end a1 : show delete message on success*/
?>
<?php /*start : email search form - line no 23 to 43*/?>
<div class="row">
<div class="col-md-4 col-md-offset-4 buffer-bottom-md"> <?php echo validation_errors(); ?>
<?php
$attributes = array('style' => 'padding:0;');
echo form_open(base_url('users/index'), $attributes);
?>
<table width="100%" cellpadding="5">
<tr>
<td><?php
$data_email = array('name' => 'email_id', 'class' =>'form-control', 'placeholder' =>'Email');
echo form_input($data_email);
?></td>
</tr>
<tr>
<td class="text-center"><input class="btn btn-primary btn-block" type="submit" name="search" value="Search"/ >
<?php echo anchor("users/reset","reset");?></td>
</tr>
</table>
</form>
</div>
</div>
<?php /*end : email search form*/ ?>
<?php echo $this->pagination->create_links();?>
<table class ="table">
<tr>
<td><strong>User Id</strong></td>
<td><strong>Username</strong></td>
<td><strong>Name</strong></td>
<td><strong>Company</strong></td>
<td><strong>Telephone</strong></td>
<td><strong>Mobile</strong></td>
<td><strong>Email</strong></td>
<td><strong>Website</strong></td>
<td><strong>status</strong></td>
<td></td>
<?php
if (isset($show_all))
{
?><td colspan=2><a class="btn btn-primary btn-block" href="<?php echo base_url('users/')?>">Show only active users</td><?php
}
else
{
?><td colspan=2><a class="btn btn-primary btn-block" href="<?php echo base_url('users/all')?>">Include deleted users</td><?php
}
?>
</tr>
<?php
/*start a2 - show edit link for each user - changes made on line no36 and 48 */
foreach($users as $row =>$value)
{
$status= (html_escape($value['status'])==0) ? "inactive" : "active";
echo "<tr>
<td><a title = 'Click to view details of this user' href = '".base_url('Users/search/'.html_escape($value['id']))."'>".html_escape($value['id'])."</a></td>
<td>".html_escape($value['username'])."</td>
<td>".html_escape($value['firstName'])." ".html_escape($value['surName'])."</td>
<td>".html_escape($value['company'])."</td>
<td>".html_escape($value['telephone'])."</td>
<td>".html_escape($value['mobile'])."</td>
<td>".html_escape($value['email'])."</td>
<td>".html_escape($value['website'])."</td>
<td>".$status."</td>
<td><a href = " . base_url("users/edit/".html_escape($value['id'])) . ">Edit</a></td>";
//echo $status; die();
echo "<td><div id='a' data-inactive='deleted'><a href = " . base_url('Users/delete/' . html_escape($value['id']));?> onclick = 'return confirm("Really delete this user?")'<?php echo ">Delete</a</td></div>";
echo "<td><div id='i' data-active='active'><a href = " . base_url('Users/reactivate/' . html_escape($value['id']));?> onclick = 'return confirm("Reactivate this user?")'<?php echo ">Reactivate</a</td></div>";
echo "</tr>";
}
/*end a2- show edit link for each user*/
?>
</table>
<?php echo $this->pagination->create_links();?>
<div class="row">
<div class="col-md-12">
<hr>
</div>
</div>
</div>
</div>
</div>
<?php /*start a3 - call required jquery and bootstrap.js file to show delete message*/?>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.js"></script>
<?php
/*end a3 - call required jquery and bootstrap.js file to show delete message*/
?>
<script>
//var mydata = $("a").data();
$("#i").hide();
</script>
생성 된 html을 공유 할 수 있다면 더 좋을 것입니다. –
@ArunPJohny 지금 설정하고 몇 분 후에 다시 확인하겠습니다. – Bobby
답변
마크 업이 깨졌습니다.
<tr>
의 직접적인 자손으로 Div를 가질 수 없으므로td
안에 들어가서<div
을 닫으십시오 !!!또한, 귀하의 변수를 설정하는 더 우아한 방법을, 대신 경우/else 문이 시도 :
당신이 겪고있는 또 다른 문제는 당신이 ID의 여러 인스턴스를 가지고있다 . 해당 액티브/비활성을 클래스 또는 다른 데이터 프로퍼티로 변경하십시오.
출처
2014-10-04 01:11:09 superUntitled
귀하의 의견을 반영하여 변경 사항을 업데이트했습니다. 지금은 단순히 내 기능을 구축하기 위해 숨길 ID를 선택하는 시점에 있습니다. 그러나 이것을 숨길 때 foreach 루프의 모든 링크 대신 하나의 링크 만 "다시 활성화"됩니다. – Bobby
두 개 이상의 요소에서이 작업이 필요한 경우 ID가 아닌 클래스를 사용해야합니다. id는 페이지에서 고유해야합니다 ... 페이지 당 하나의 '#active'또는 '#inactive'요소 만있을 수 있습니다. 둘 이상을 추가해야하는 경우 ids 대신 클래스를 사용하십시오. – superUntitled
첫째, 의미 론적 마크 업을 중단시키는 DIV에 TD를 래핑 할 수 없습니다. DIV를 TD 안에 넣어야합니다.
두 번째로 여러 요소에 동일한 ID (식별자)를 사용하면 안되며 의미 기호를 더 이상 사용하지 않습니다. 적절한 HTML 마크 업과 DOM 요소를 대상으로 자바 스크립트를 사용하는 방법에 대해 좀 더 읽어야합니다.
출처
2014-10-04 01:16:42 bgallagh3r
귀하의 의견을 반영하도록 변경 사항을 업데이트했습니다. 지금은 단순히 내 기능을 구축하기 위해 숨길 ID를 선택하는 시점에 있습니다. 그러나 이것을 숨길 때 foreach 루프의 모든 링크 대신 하나의 링크 만 "다시 활성화"됩니다. – Bobby
관련 문제