简体   繁体   English

javascript参数传递?

[英]javascript parameter passing?

I am not quite sure how to describe what I want, but here goes nothing. 我不太确定如何描述我想要的东西,但是什么也没做。

I am trying to have multiple buttons that will show/hide a div (I have that part set up already). 我正在尝试有多个按钮来显示/隐藏div(我已经设置了该部分)。 I would like the button to have two values (number and letter) that will then fill in a parameter for another button's onclick event (these need to change however depending on what button was originally clicked. 我希望按钮具有两个值(数字和字母),然后将为另一个按钮的onclick事件(这些需要更改,但取决于最初单击的按钮是什么)填充参数。

For example, I click button1 which has values a and 1. This then fills in the parameters for the onclick event for button 3. Or I can click button 2 which has b and 2 and this will fill in b and 2 for the parameters for button 3 (so button 3 on click parameters need to change) 例如,我单击具有值a和1的button1。这将为按钮3填充onclick事件的参数。或者,我可以单击具有b和2的按钮2,这将为参数b填充b和2。按钮3(因此,点击参数上的按钮3需要更改)

<input type='button' value="1" id="1" name="1" onclick="toggle();" style="background-color:lightblue; height:75px; width:75px;-webkit-appearance: none; border-radius: 70px;
" />  

That button is what needs to have the two "values" of some sort Hamburger 该按钮需要具有某种汉堡包的两个“值”

That's the button that needs the values passed to the event. 这是需要将值传递给事件的按钮。

var toggle = function() {
    var mydiv = document.getElementById('table1');
    if (mydiv.style.display === 'block' || mydiv.style.display === '')
        mydiv.style.display = 'none';
    else
        mydiv.style.display = 'block'
}

It sounds to me like some having the function set some global variables would do the trick. 在我看来,有些人可以通过函数设置一些全局变量来解决问题。 Not entirely sure of what you're trying accomplish: 不确定您要完成的工作:

You can pass whatever parms you want to toggle: 您可以传递要切换的任何参数:

 <input type='button' value="1" id="1" name="1" onclick="toggle(1, a)" /> 

And then set them as global vars in in your JS: 然后在您的JS中将它们设置为全局变量:

 var parm1, parm2; var toggle = function(myChar, myInt) { parm1 = myChar; parm2 = myInt; } 

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

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