如何在从下拉列表中选择不同的值后更新和调用javascript函数

How to update and recall a javascript function after select different value from select dropdown

本文关键字:更新 调用 函数 javascript 下拉列表 选择      更新时间:2023-09-26

嗨,我的页面底部有这个javascript。

    var e = document.getElementById("path_chooser");
    var path= e.options[e.selectedIndex].value;
    function update()
    {
    imgObj = document.getElementById('img1');
    if (!isChrome) imgObj.src = img.src;
    img.src = "cams/camera1.php?canal="+path+"&t="+(unique_name++);
    if (originalWidth == 0)
    {........ bla bla bla

我有一个选择下拉

                <select id="path_chooser" >
                <option value="1">camera1</option>
                <option value="2" selected="selected">camera2</option>
                <option value="3">camera3</option>
                </select>

这个javascript更新div中的相机图像,它工作正常,现在我需要javascript在用户更改所选相机时更新var"path"。

当我更改选择时,我会更新var路径,但div没有刷新,请告诉我怎么做。

非常感谢

Diego

下面是一个处理下拉框的onchange事件的示例:

<select id="path_chooser" onchange="getOption(this)">
            <option value="1">camera1</option>
            <option value="2" selected="selected">camera2</option>
            <option value="3">camera3</option>
            </select>
 function getOption(v)
 {
   var path= v.options[v.selectedIndex].value;
   imgObj = document.getElementById('img1');
   if (!isChrome) imgObj.src = img.src;
   img.src = "cams/camera1.php?canal="+path+"&t="+(unique_name++);
   .............................
 }