我的选择代码在
之下<select id="ddlLanguages" class="form-control">
@foreach($Languages as $Language)
<option onchange="location.href = {!! URL('Tr/' . '/' . $Language->LID) !!}"
value="{!! $Language->LanguageID !!}">{!! $Language->Language !!}</option>
@endforeach
</select>
这会产生html以下
<select id="ddlLanguages" class="form-control">
<option onchange="location.href = http://localhost/Learning/public/Translation/1"
value="1">English</option>
<option onchange="location.href = http://localhost/Learning/public/Translation/2"
value="2">French</option>
</select>
问题是这部分"location.href = http://localhost/Learning/public/Translation/1"
我在网址中遗漏了一些格式。
你能指导我正确的道路吗?
答案 0 :(得分:0)
改变这个:
For lRow = 1 To oTbl.Rows.Count
For lCol = 1 To oTbl.Columns.Count
With oTbl.Cell(lRow, lCol).Shape.TextFrame.TextRange
.Font.Name = "Arial"
.Font.Size = 30
End With
Next
Next
到此:
<option onchange="location.href = {!! URL('Tr/' . '/' . $Language->LID) !!}"
value="{!! $Language->LanguageID !!}">{!! $Language->Language !!}</option>
您传递给location.href的网址必须是字符串,这就是您需要用单引号括起整个网址的原因。
答案 1 :(得分:0)
试试这个:
<select id="ddlLanguages" class="form-control">
@foreach($Languages as $Language)
<option data-url="{!! URL('Tr/' . '/' . $Language->LID) !!}"
value="{!! $Language->LanguageID !!}">{!! $Language->Language !!}</option>
@endforeach
</select>
<script>
$('#ddlLanguages').on('change', function () {
var url = $(this).attr('data-url'); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
</script>
答案 2 :(得分:0)
onchange
不应该放在<option>
上,而应放在<select>
上,因为<option>
没有改变。选择一个选项即可更改<select>
。如果您想根据<option>
选项重定向。执行以下操作:
var select = document.getElementById('ddlLanguages');
select.onchange = function() {
location.href = select[select.selectedIndex].getAttribute('data-location');
}
请参阅下面有关此javascript代码段的jQuery版本。
将此javascript放在页面中的某个位置。而您的<options>
应该有data-location
。
<option data-location="{!! URL('Tr/' . '/' . $Language->LID) !!}" value="{!! $Language->LanguageID !!}">{!! $Language->Language !!}</option>
或者您可以将选项更改为click
上的“重定向”:
<select id="ddlLanguages" class="form-control">
<option onclick="location.href = http://localhost/Learning/public/Translation/1" value="1">English</option>
<option onclick="location.href = http://localhost/Learning/public/Translation/2" value="2">French</option>
</select>
jQuery的:
$(function() {
$('#ddlLanguages').change(function(){
location.href = $(this).data('location');
});
});
答案 3 :(得分:-1)
JS代码
$('#ddlLanguages').change(function(){
location.href = $(this).find(":selected").attr('data-url');
});
服务器端
<select id="ddlLanguages" class="form-control">
@foreach($Languages as $Language)
<option data-id="{!! URL('Tr/' . '/' . $Language->LID) !!}"
value="{!! $Language->LanguageID !!}">{!! $Language->Language !!}</option>
@endforeach
</select>