Foreach 选择定义 textarea 值

我正在寻找一种使选择选项更改 textarea 值的方法。

我正在使用 @foreach($collection as $item) 作为我的选项。

http://img3.mukewang.com/61c52f9e00012a4c03390249.jpg

<select class="form-control" style="margin-bottom: 5px">

    <option value="">Choix modèle de réponse</option>

    @foreach($modeles as $modele)

    <option value="{{ $modele->id }}">{{ $modele->title }}</option>

    @endforeach

</select>


<textarea class="form-control" name="texte" id="texte" required>GRDF Bonjour</textarea>

我已经尝试过搜索,但我只找到了不适用于 foreach 的方法。


偶然的你
浏览 145回答 1
1回答

明月笑刀无情

<select class="form-control" style="margin-bottom: 5px" id="myselectbox">&nbsp; &nbsp; <option value="">Choix modèle de réponse</option>&nbsp; &nbsp; @foreach($modeles as $modele)&nbsp; &nbsp; <option value="{{ $modele->id }}">{{ $modele->title }}</option>&nbsp; &nbsp; @endforeach</select><textarea class="form-control" name="texte" id="texte" required>GRDF Bonjour</textarea><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" type="text/javascript"></script><script>&nbsp;$(document).on('change','#myselectbox',function(){&nbsp; &nbsp; var value =&nbsp; $(this).val();&nbsp; &nbsp;// here is the selectbox value&nbsp; &nbsp; $("#texte").val(value);&nbsp; &nbsp;// here put selectbox value in textarea});</script>如果您有多次选择框和文本区域,则:-@foreach($collection as $key => $item)<select class="form-control selectbox" style="margin-bottom: 5px" id="myselectbox-{{$key}}">&nbsp; &nbsp; <option value="">Choix modèle de réponse</option>&nbsp; &nbsp; @foreach($modeles as $modele)&nbsp; &nbsp; <option value="{{ $modele->id }}">{{ $modele->title }}</option>&nbsp; &nbsp; @endforeach</select><textarea class="form-control" name="texte" id="texte-{{$key}}" required>GRDF Bonjour</textarea>@endforeach<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" type="text/javascript"></script><script>&nbsp;$(document).on('change','.selectbox',function(){&nbsp; &nbsp; var value =&nbsp; $(this).val();&nbsp; &nbsp;&nbsp; &nbsp; var id = $(this).attr('id');&nbsp; &nbsp; var key = id.substr(12);&nbsp; &nbsp; $("#texte-"+key).val(value);&nbsp; &nbsp;});</script>
打开App,查看更多内容
随时随地看视频慕课网APP