1

私はこの問題に直面しているこのプロジェクトに取り組んでいます。ロード後にクリックすると、コードが機能します。各ユーザーに id を使用しました。これはアクティブ/非アクティブ ユーザー用のコードです。ID を各テキストボックスとスパンに渡しました。機能していません。この問題を解決する方法についていくつかのアイデアを提供してください。PHP コード:

    <!--top section start-->
<?php $this->load->view("header");?>
    <div id="wrapper" style="height: auto;">
         <div class="user_intro">
            <table  width="600" height="300">
             <th style="text-align:left;">First Name</th>
             <th style="text-align:left;">Email</th>
             <th style="text-align:center;">Active Status </th>
         <?php 
        foreach($result as $user)
        {?>
             <tr>
                 <td style="text-align:left;"><a href="<?php echo base_url()?>siteadmin/home/userdetail?userid=<?php echo $user->user_id; ?>"><?php echo $user->first_name;?></a></td>
                 <td style="text-align:left;"><a href="<?php echo base_url()?>siteadmin/home/userdetail?userid=<?php echo $user->user_id; ?>"><?php echo $user->email;?></a></td>
                 <?php if ($user->status == 1) { ?>
                 <td style="text-align:center;"><input type="button" id="<?php echo $user->user_id; ?>" value="" class="on" onclick="togglestyle(this,this.id)" /> </td>              
                 <td><span id="reason_<?php echo $user->user_id; ?>"><input type="text" value="<?php echo $user->reason; ?>" /> </span></td>
                <?php } 
                else {?>
                 <td style="text-align:center;"><input type="button" id="<?php echo $user->user_id; ?>" value="" class="off" onclick="togglestyle(this,this.id)" /> </td>   
                 <td><span id="reason_<?php echo $user->user_id; ?>"><input type="text" value="<?php echo $user->reason; ?>" /> </span></td>
                 <?php } ?>
             </tr>
        <?php }
        ?>
        </table>

        </div>
    </div>

    <!--fotter section start-->

</div> <?php $this->load->view("footer"); ?>

ヘッダーファイルに追加したjavascriptコード.:

<script type="text/javascript">
function togglestyle(el, id) {
    if (el.className == "on") {
        $("#reason_" + id).show();
        $.ajax({
            type: "POST",
            url: "statuson",
            data: "userid=" + id,
            success: function (html) {
                if (html == 'true') {
                    el.className = "off";

                }
            },
        });
    } else {
        $("#reason_" + id).hide();
        $.ajax({
            type: "POST",
            url: "statusoff",
            data: "userid=" + id,
            success: function (html) {
                if (html == 'true') {
                    el.className = "on";
                }
            },
        });
    }
}
</script>
4

4 に答える 4

0

これを div style="display:none; で使用してください。

于 2013-06-06T12:46:58.527 に答える
0

シンプル...ドキュメントの読み込み時に、次のようなデフォルト値で関数を呼び出します

<script type="text/javascript">
    $(document).ready(function(){
         togglestyle(el,id); //Here el,id are default values for those you need to hide initially
    });
</script>

または、最初にすべてのテキストボックスを非表示にする場合は、次のように試してください

$(document).ready(function(){
    $("span[id^='reason'] input[type='text']").hide();
})
于 2013-06-06T12:05:55.090 に答える
0

jQuery("input[name='multiple_location']").on('change', function () {
    if (jQuery('input[name="multiple_location"]:checked').val()=='yes') {
    jQuery("#primary_location_text").css('visibility', '');
    } else {

    jQuery("#primary_location_text").css('visibility', 'hidden');
    }
});
于 2017-07-06T14:07:49.707 に答える