我有一个javascript onchange列表框它显示值,但我插入灯箱代码不显示。我想添加值列表框链接,因为我想编辑页面是灯箱。
示例 - &gt; <a class="various" data-fancybox-type="iframe" href="edit.php?id=<?**listbox value is onchange**?>">Edit</a>
如何将返回值列表框用于变量?
此代码更改列表框
<label for="country">Country</label>
<select name="country" id="country">
<option value="1">Thailand</option>
<option value="2">England</option>
<option value="3">Japan</option>
</select>
<div id="selected_value"></div>
<label for="country">Country:</label>
<input type="text" name="country" id="country" class="country">
<script type="text/javascript">
$('#country').on("change", function(){
//Get the selected value
var selected_value = $("#country option:selected").val();
//Write the selected value to our div
('#selected_value').html(selected_value);
});
</script>
灯箱代码
<script type="text/javascript" src="../wp-content/plugins/pop-up/include/js/scripts/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="../wp-content/plugins/pop-up/include/js/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="../wp-content/plugins/pop-up/include/js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="../wp-content/plugins/pop-up/include/js/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<script type="text/javascript">
$(document).ready(function($) {
$(".various").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '80%',
height : '80%',
autoSize : false,
closeClick : false,
hideOnOverlayClick : false,
openEffect : 'none',
closeEffect : 'none',
type : 'iframe',
onClosed : function() {
parent.location.reload(true);
}
});
});
</script>
答案 0 :(得分:1)
要在选择新选项时更新链接,您可以执行以下操作:
$('a.various').attr('href','edit.php?id='+selected_value);
更新后的更新功能版本:
$('#country').on("change", function(){
// Get the selected value
var selected_value = $("#country option:selected").val();
// Update lightbox edit hyperlink
$('a.various').attr('href','edit.php?id='+selected_value);
});
我认为你不需要#selected_value div。