选择选项可更改图像的不透明度
select option to change image opacity
我需要一些关于选择选项的帮助。我有一个选择下拉列表,当选择或更改时,我需要图像不透明度从0.3变为1,但不能使用预定义的选项值。有人能帮忙吗?
这是(坏的)脚本:
<script type="text/javascript">
window.onload = function() {
document.getElementById('input_25_custom_1011_0').onchange = img }
function img(){
if (document.getElementById('input_25_custom_1011_0').selected == true ){
document.getElementById('id_46').style.opacity = "1"; }
else {
document.getElementById('id_46').style.opacity = "0.3"; }
}
</script>
以及相关的html:
<img alt="" class="form-image" border="0" src="http://www.jotform.com/uploads/TeckStyle/form_files/frame.png" height="334" width="225" />
<select class="form-dropdown validate[required]" name="q25_input25[special_1011][item_0]" id="input_25_custom_1011_0">
<option value="Standard"> Standard </option>
<option value="Standard & Rider 1"> Standard & Rider 1 </option>
<option value="Standard & Rider 2"> Standard & Rider 2 </option>
<option value="Standard, Rider 1 & 2"> Standard, Rider 1 & 2 </option>
</select>
编辑:更新和校正的输入元素。
我认为这部分:if(document.getElementById('put_25_custom_1011_0').selected==true){
需要定义选择哪个选项。。。
添加img id[id="id_46"]
使用选择标签的id更新您的窗口加载功能
[window.onload=函数(){document.getElementById('put_25_custom_1011').ochange=img}]
<img alt="" id="id_46" class="form-image" border="0" src="http://www.jotform.com/uploads/TeckStyle/form_files/frame.png" height="334" width="225" />
<select class="form-dropdown validate[required]" name="q25_input25[special_1011][item_0]" id="input_25_custom_1011_0">
<option value="Standard"> Standard </option>
<option value="Standard & Rider 1"> Standard & Rider 1 </option>
<option value="Standard & Rider 2"> Standard & Rider 2 </option>
<option value="Standard, Rider 1 & 2"> Standard, Rider 1 & 2 </option>
</select>
</body>
<script type="text/javascript">
window.onload = function() {
document.getElementById('input_25_custom_1011_0').onchange = img }
function img(){
if (document.getElementById('input_25_custom_1011_0').selected == true ){
document.getElementById('id_46').style.opacity = "1"; }
else {
document.getElementById('id_46').style.opacity = "0.3"; }
}
</script>
如果您使用的是jQuery,您也可以使用以下脚本
$("#input_25_custom_1011_0").on("change",function(){
$("img" ).fadeTo( "slow" , 0.3, function() {
// Add your animation logic here.
// Animation done.
});
});
获取img()函数的ID不正确。在window.load上,没有ID为input_25_custom_1011
的元素。
检查一下这把小提琴。http://jsfiddle.net/tqdjshae/
我用input_25_custom_1011
替换了select标签上的ID,它就工作了。
相关文章:
- 如何在页面向下滚动时获得图像以获得不透明度
- 在Materialize设计中删除转盘图像的不透明度
- 选择选项可更改图像的不透明度
- 使用媒体查询设置背景图像的不透明度
- 将鼠标悬停在图像上,图像的不透明度和图像下方标题的颜色会发生变化..同样,当标题变成两行时,它会破坏格式
- 如何使用for循环更改图像的不透明度以创建渐变照明效果
- 将不透明度更改为复选框图像
- JavaScript使用计时器和不透明度通过淡入淡出缓慢更改图像
- 如何使用画布更改图像的不透明度,然后将其加载到画布中的另一个图像上?-HTML
- 通过下拉菜单更改图像的不透明度
- 为什么图像样式不透明度不会更改画布中的图像对象
- 悬停标题更改不透明度图像时
- 将一个图像放在另一个图像上方,不具有不透明度
- 幻灯片 具有不透明度的阵列图像(淡入淡出)
- 背景图像不透明度问题
- 更改图像属性更改时的不透明度
- 传递图像以获得不透明度效果
- kineticJS按顺序加载图像(并设置fillPatternImg)不透明度补间不起作用
- Javascript-根据函数的结果更改图像的不透明度
- 使用插件将所有背景图像的不透明度设置为0