通过<a href="#myModel"></a>标记传递值(使用html中的链接传递数据值)?

时间:2015-09-22 03:35:53

标签: javascript php html html5 laravel-5

我使用href调用同一页面对话框id。

这是我的代码部分

                  <tbody>                  

                        @foreach ($basl_officers as $basl_officer)
                        <tr >
                            <td><a href="#myModal" data-toggle="modal" data-target="#myModal"> {{ $basl_officer->code }} </a></td>        

                            <td align='center'>
                                {!! Form::open(['method' => 'DELETE', 'route'=>['basl_officers_page.destroy',$basl_officer->id]]) !!}
                                <a href="{{route('basl_officers_page.edit',$basl_officer->id)}}" class="btn btn-default btn-sm"> <span class="glyphicon glyphicon-pencil"></span> </a> &nbsp &nbsp
                                <button type="submit" class="btn btn-default btn-sm" onclick="return confirm('Are you sure?')"> <span class="glyphicon glyphicon-trash"></span> </button> 
                                {!! Form::close() !!}
                            </td> 
                        </tr>


                        @endforeach

                    </tbody>

//模型对话框代码

 <!-- Modal -->
<div class="modal fade" id="myModal" role="dialog"> 
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="btn btn-default" style='float: right;' data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span></button>
                <a href="#" class="btn btn-default" style='float: right;'> <span class="glyphicon glyphicon-trash"></span> </a>
                <a href="#" class="btn btn-default" style='float: right;'> <span class="glyphicon glyphicon-pencil"></span> </a>
                <h4 class="modal-title">BASL  Officers  Details {{ $basl_officer }} </h4>
            </div>



            <!-- text input -->
            <div class="modal-body">

                {!! Form::label('o_code', 'Officers Code: '); !!}
                {!! Form::text('officers_code', null, ['class' => 'form-control', 'id' => 'officers_code','disabled' => 'disabled']); !!}


                {!! Form::label('o_name', 'Officers Name: '); !!}
                {!! Form::text('officers_name', null, ['class' => 'form-control', 'id' => 'officers_name','disabled' => 'disabled']); !!}


            </div>
        </div>

    </div>
</div>

我想将select table row,$ basl_officer对象传递给这个#myModal对话框。有没有办法做到这一点?请尽快给予专家帮助。从一周开始,我尝试以不同的方式。我使用Laravel 5框架。

///////////////////全码////////////////////////// /////////////////////

    @extends('layouts.app')

@section('slide_bar')
@include('layouts.master_entry_slide_bar')
@endsection

@section('content')




<section class="content-header">
    <h1>BASL  Officers  <small>page </small></h1>
</section>


<br/>

<!-- Main content -->
<section class="content fluid">
    <div class="row">
        <div class="box">
            <div class="gap">
                <div class="box-body">
                    <table id="example1" class="table table-bordered table-striped">
                        <col width='auto'>
                        <col width='auto'>
                        <col width='100'>

                        <thead>
                            <tr>
                                <th>BASL Officers Code</th>
                                <th>BASL Officers Name</th>
                                <th><p id='buttons'> <a href="{{ route('basl_officers_page.create')}}" class="btn btn-success"> <strong> Add New Officers &nbsp </strong> <span class="glyphicon glyphicon-plus"></span> </a> </p></th>
                        </tr>
                        </thead>
                        <tbody>                  

                            @foreach ($basl_officers as $basl_officer)
                            <tr >
                                <td><a href="#myModal" data-toggle="modal" data-target="#myModal">  {{ $basl_officer->code }} </a></td>        
                                <td><a href="#" >{{ $basl_officer->officerName }} </a></td>        
                                <td align='center'>
                                    {!! Form::open(['method' => 'DELETE', 'route'=>['basl_officers_page.destroy',$basl_officer->id]]) !!}
                                    <a href="{{route('basl_officers_page.edit',$basl_officer->id)}}" class="btn btn-default btn-sm"> <span class="glyphicon glyphicon-pencil"></span> </a> &nbsp &nbsp
                                    <button type="submit" class="btn btn-default btn-sm" onclick="return confirm('Are you sure?')"> <span class="glyphicon glyphicon-trash"></span> </button> 
                                    {!! Form::close() !!}
                                </td> 
                            </tr>
                            @endforeach

                        </tbody>
                        <tfoot>
                            <tr>
                                <th>BASL Officers Code</th>
                                <th>BASL Officers Name</th>
                                <th></th>
                            </tr>
                        </tfoot>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>

    </div><!-- /.row -->

</section><!-- /.content -->

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog"> 
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="btn btn-default" style='float: right;' data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span></button>
                <a href="#" class="btn btn-default" style='float: right;'> <span class="glyphicon glyphicon-trash"></span> </a>
                <a href="#" class="btn btn-default" style='float: right;'> <span class="glyphicon glyphicon-pencil"></span> </a>
                <h4 class="modal-title">BASL  Officers  Details {{ $basl_officer }} </h4>

            </div>



            <!-- text input -->
            <div class="modal-body">
                <p>One fine body&hellip;</p>

                {!! Form::label('o_code', 'Officers Code: '); !!}
                {!! Form::text('officers_code', null, ['class' => 'form-control', 'id' => 'officers_code','disabled' => 'disabled']); !!}


                {!! Form::label('o_name', 'Officers Name: '); !!}
                {!! Form::text('officers_name', null, ['class' => 'form-control', 'id' => 'officers_name','disabled' => 'disabled']); !!}


            </div>
        </div>

    </div>
</div>


<script>
            var name = document.getElementById("master_entry");
            document.getElementById("master_entry").className = "active";
            var slide_bar_element = document.getElementById("bd_menu");
            document.getElementById("bd_menu").className = "active";
            var slide_bar_element = document.getElementById("bd_submenu1");
            document.getElementById("bd_submenu1").className = "active";

</script>



<script>            
    $('#myModal').on('shown.bs.modal', function (e) {
             $('.modal-body').text($(e.relatedTarget).text());
    }
</script>




@endsection

我想在此对话框中显示选定的表格行数据

I want to show selected table row data value in this dialog box

1 个答案:

答案 0 :(得分:1)

您可以使用bootstrap-modal的{​​{1}}事件并捕获触发shown.bs.modal的{​​{1}},如下所示:

related target

<强> DEMO

<强>更新

通过查看您的代码结构,我可以为您提供一个可能的解决方案,如下所示:

modal

<强> DEMO