【发布时间】:2019-03-13 15:57:56
【问题描述】:
也许有人可以帮助我解决我的问题?我所需要的只是显示带有内容的 div(div 的架构实际上总是相同的,但内容(id、名称等)根据用户的选择而有所不同。例如,用户选择模块 1,下面显示模块 1,选择模块 2并显示模块 2。我想我可以使用 ajax 或 jQuery 来完成,但我尝试的所有方法都无法正常工作。我的逻辑是:
<script>
function showSmtpType() {
var selectBox = document.getElementById('type');
var userInput = selectBox.options[selectBox.selectedIndex].value;
@foreach($modules as $module)
if (userInput == "{{ route("module", ['module' => ($module->id)]) }}"){
document.getElementById('moduleType').style.visibility ='visible';}
else {
document.getElementById('moduleType').style.visibility ='hidden';
}
return false;
@endforeach
}
</script>
<main class="main">
<div class="container-fluid">
<div class="animated fadeIn">
<div class="row">
<div class="col-sm-6 col-lg-8">
<h4 class="head">Module-setup</h4>
<div class="col-md-9 col-xl-6">
<span class="head-2">Module:</span>
<select class="dropdownHeader function" id="type" name="type" onchange="return showSmtpType();">
@foreach($modules as $module)
<option value="{{ route("module", ['module' => ($module->id)]) }}">{{$module->name }}</option>
@endforeach
</select>
</div>
{{--Begin of description--}}
<div class="card-custom bg-primary-2" >
<div class="card-body pb-0">
@foreach($modules as $k=>$item)
@if($k ==0)
<div class="btn-group float-right">
<button class="btn btn-transparent dropdown-toggle p-0" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="icon-settings"></i>
</button>
</div>
<div class="text-value">
@if($item->enabled == 1)
<input checked name="enabled" type="checkbox" value=""><span class="checkbox">
</span>
@endif
@if ($item->enabled ==0)
<input name="enabled" type="checkbox" value=""><span class="checkbox"></span>
@endif
Enabled </span><br/>
@if($item->active == 1)
<input checked name="active" type="checkbox" value=""><span class="checkbox">
</span>
@endif
@if($item->active == 0)
<input name="active" type="checkbox" value=""><span class="checkbox">
@endif
Active</span>
@endif
@endforeach
</div>
<div id="moduleType" style="visibility: hidden;">
<span style="margin-right: 40px;">Database:</span>
{!! Form::text('database',isset($module->DB)? $module->DB : old('DB'),['placeholder' =>'Database'])!!}
<br/> <br/>
<span style="margin-right: 75px;">Path:</span>
{!! Form::text('path',isset($module->path)? $module->path : old('PATH'),['placeholder' =>'Path'])!!}
<br/><br/>
<span style="margin-right: 5px;">Friendly name:</span>
{!! Form::text('standardname',isset($module->standardname)? $module->standardname : old('DB'),['placeholder' =>'Friendly name'])!!}
<br/><br/>
<span style="margin-right: 20px;">Icon(20x20):</span>
@if(isset($module->icon))
<li style="list-style: none;" class="textarea-field">
<label>
<span class="label">Image:</span>
</label>
{{ Html::image(asset('/images/img/icons'.$module->icon->path)) }}
{!! Form::hidden('old_image',$module->icon->path) !!}
</li>
@endif
<li style="list-style: none;" class="text-field">
<div class="input-prepend">
{!! Form::file('image',['class'=>'filestyle', 'data-buttonText'=>'choose image','data-buttonName'=>'image'])!!}
</div>
</li>
</div>
</div>
<div class="chart-wrapper mt-3 mx-3" style="height:70px;">
<canvas class="chart" id="card-chart1" height="70"></canvas>
</div>
</div>
{{--End of div with description of module--}}
</div>
</div>
</div>
</div>
</main>
将不胜感激!谢谢!
【问题讨论】:
标签: jquery ajax laravel laravel-blade