JavaScript
22
Вклад в тег
<select id="dynamic-select">
<option value="http://www.google.com/">Google</option>
<option value="http://www.youtube.com/">YouTube</option>
<option value="http://www.yandex.ru/">Yandex</option>
</select>
<script>
$('#dynamic-select').bind('change', function () {
var url = $(this).val();
if (url != '') {
window.location = url;
}
return false;
});
</script>
<select id="dynamic-select">
<option id="s1" value="test.html?s=s1">Google</option>
<option id="s2" value="test2.html?s=s2">YouTube</option>
<option id="s3" value="test3.html?s=s3">Yandex</option>
</select>
<script>
$(document).ready(function () {
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
var selected = $.urlParam('s');
if (selected){
$("#dynamic-select option[id="+selected+"]").prop("selected", "selected");
}
$('#dynamic-select').bind('change', function () {
var url = $(this).val();
if (url != '') {
window.location = url;
}
return false;
});
});
</script>