为什么我的Button的onClick()方法无用?

时间:2016-04-28 12:13:28

标签: javascript html

以下是我的html布局的一部分(使用 sciter 框架):

 <div id="volume_micphone_slider" style="z-index:1;">
    <input id="volume_slider" class="volume_slider" type="vslider" name="p1c" max="100" value="20" buddy="p1c-buddy" />
 </div>
 <div>
     <button id="volume_show" class="volume_show"  ></button>
     <button id="micphone_show" class="micphone_show"></button>
 </div>

这是Button的onClick()方法(使用 tiscript ):

var volume_flag=1;
function volume_ctrl()
{
   if(volume_flag)
   {                       
      $(#volume_slider).style#display ="none";
     volume_flag=0;
   }
   else
   {
      $(#volume_slider).style#display ="inline-block";
      volume_flag=1;
   }
}
$(#volume_show).onClick = function()
{
  volume_ctrl();
}

但是这种方法没有用。请帮我弄清楚我的问题。谢谢。

2 个答案:

答案 0 :(得分:0)

代码中的多个问题,如内联解释

var volume_flag=1;
function volume_ctrl()
{
   if(volume_flag)
   {                       
      $("#volume_slider").style.display ="none"; //selector in quotes and . before style
     volume_flag=0;
   }
   else
   {
      $("#volume_slider").style.display ="inline-block";
      volume_flag=1;
   }
}
$("#volume_show").onclick = function() //small c instead of C in onclick
{
  volume_ctrl();
}

答案 1 :(得分:-1)

Hello亲爱的,这是纯粹的javascript代码

        var volume_flag = 1;
        function volume_ctrl() {
            if (volume_flag) {
                document.getElementById('volume_slider').style.display = "none";
                volume_flag = 0;
            } else {
                document.getElementById('volume_slider').style.display = "inline-block";
                volume_flag = 1;
            }
        }


        document.getElementById('volume_show').addEventListener("click", function() {
            volume_ctrl();
        })