doob0526 2015-09-22 03:35
浏览 112
已采纳

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

I use a href to call same page dialog box id.

this is my part of code

                  <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>

//Model dialogue box code

 <!-- 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>

I want to pass select table row , $basl_officer object to this #myModal dialogue.is there any way to do this? please expect some expert help as soon as possible. since one week I try to do this different way .I use Laravel 5 framework.

///////////////////full code///////////////////////////////////////////////

    @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

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

  • 写回答

1条回答 默认 最新

  • douchen4534 2015-09-22 03:45
    关注

    You can make use of bootstrap-modal's shown.bs.modal event and capture the related target which triggered the modal as below:

    $('#myModal').on('shown.bs.modal', function (e) {
      alert($(e.relatedTarget).text());
    })
    

    DEMO


    Update

    By seeing your code structure, I can give you one possible solution which is as below:

    <script type="text/javascript">
        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";
    
        //modal part
        $('#myModal').on('shown.bs.modal', function (e) {
            $('.modal-body #officers_code').val($(e.relatedTarget).text());
            //assign officers code to officers_code textbox
            $('.modal-body #officers_name').val($(e.relatedTarget).closest('td').next().find('a').text())
            //get the relatedTarget elements next anchor element and assign its text to officers_name textbox
        })
    </script>
    

    DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘