单击图像按钮时,html按钮不会隐藏

时间:2014-09-25 05:29:48

标签: asp.net

我有一个html图像按钮和两个html按钮。我想隐藏图像按钮上的两个按钮单击。 但每当我按下图像按钮时,页面都会重新加载并且按钮可见。 当我不隐藏Stop_Camera_view按钮时,一切正常 这是我的代码,

<script type="text/javascript">
function HideStartStopButton() {
         document.getElementById("Start_Camera_view").hidden = true;
         document.getElementById("Stop_Camera_view").hidden = true;
     }    
</script>
<input id="imgBtnSequencing" type="image" src="../images/update_btn.gif" value="Sequencing" onclick="HideStartStopButton();return false;"/>
<button id="Start_Camera_view" name="Start_Camera_view" type="button" onclick="StartSequencingTimer()">Start</button>
<button name="Stop_Camera_view" type="button" onclick="StopSequencingTimer()" title="Stop all cameras">Stop</button>

3 个答案:

答案 0 :(得分:0)

你忘了带第二个按钮的id。

记下第二个按钮的ID。

替换您的HTML代码

<button id="Start_Camera_view" name="Start_Camera_view" type="button" onclick="StartSequencingTimer()">Start</button>
<button name="Stop_Camera_view" type="button" onclick="StopSequencingTimer()" title="Stop all cameras">Stop</button>

用这个:

<button id="Start_Camera_view" name="Start_Camera_view" type="button" onclick="StartSequencingTimer()">Start</button>
<button id="Stop_Camera_view_2" type="button" onclick="StopSequencingTimer()" title="Stop all cameras">Stop</button> 

答案 1 :(得分:0)

您需要像这样修改脚本

<script type="text/javascript">
        function HideStartStopButton() {
            document.getElementById('<%= Start_Camera_view.ClientID %>').style.display = "none";
            document.getElementById('<%= Stop_Camera_view.ClientID %>').style.display = "none";
        }    
</script>

而且,您还需要在第二个按钮中添加ID属性,如下所示

<button ID="Stop_Camera_view" type="button" onclick="StopSequencingTimer()" title="Stop all cameras">Stop</button>

答案 2 :(得分:0)

如果您使用C#并将按钮更改为asp:ImageButton和两个asp:Button,您可以隐藏这样的按钮:

<asp:ImageButton ID="imgBtnSequencing" runat="server" ImageUrl="../images/update_btn.gif" OnClick="HideStartStopButton_Click" />

<asp:Button id="Start_Camera_view" OnClick="StartSequencingTimer_Click" runat="server" /> 

<asp:Button id="Start_Camera_view2" OnClick="StopSequencingTimer_Click" runat="server" />



 protected void imgBtnSequencing_Click(object sender, EventArgs e)
      {
          if(sender == imgBtnSequencing)
            {
                Start_Camera_view.Visible = false;
                Start_Camera_view2.Visible = false;
            }
      }