简体   繁体   English

在调用函数和定义的函数中传递与参数相同的id

[英]Passing same id as parameter in invoking function and the defined function

I have a select menu . 我有一个选择菜单。 On selecting the values it triggers getvalyear() function passing selected option as parameter. 在选择值时,它将触发getvalyear()函数,将选择的选项作为参数传递。 I need to call the getvalue() function inside display() function with same parameter described earlier. 我需要使用前面描述的相同参数调用display()函数内部的getvalue()函数。 I also have to pass the argument to display() function. 我还必须将参数传递给display()函数。

Any helps are recommended. 建议任何帮助。

Code snip of my description is described below. 我的描述的代码片段描述如下。

   <select name="year" id="year"  style="width: 200px" onchange="getvalue(this)">
              <option>--Select Year--</option>
              <option value="2014">2014</option>
              <option value="2015">2015</option>
              <option value="2016">2016</option>
              <option value="2017">2017</option>   
              <option value="2018">2018</option>
    </select>



<script type="text/javascript">

 function getvalue(ctrl1){

      var sel = ctrl1.selectedIndex; 
      var selVal1 = ctrl1.options[sel].value; 

    }

function display(clicked_id)
{
    getvalyear(id);
}

</script>

If I understood the problem, you can try this code to display select boxes manually: 如果我了解此问题,则可以尝试以下代码来手动显示选择框:

function display(clicked_id) {
    getvalue($('#' + clicked_id)[0]);
}

// select year
display('year');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM