我正在尝试使用div来显示游戏规则,因此当他们选择“按钮”时它会显示规则,但我无法通过重新选择它来关闭它。我尝试过其他一些解决方案,但它们并不是我想要的。
private void btnView_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.InitialDirectory = "C:\\";
op.Filter = "Txt files (*.txt)|*.txt|All Files (*.*)|*.*";
op.FilterIndex = 2;
if (op.ShowDialog() == DialogResult.OK)
{
textBox1.Text = op.FileName;
string path = op.FileName;
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(path))
{
while(sr.Peek() >= 0)
{
sb.Append(sr.ReadLine());
Console.WriteLine("\r\n");
}
}
richTextBox1.Text = sb.ToString();
}
}
答案 0 :(得分:0)
您可以使用toggleDiv
而非showDiv
函数检查显示样式,并将其设置为当前未设置的block
或none
。例如:
<script type="text/javascript">
function toggleDiv() {
var div = document.getElementById('howto');
div.style.display = (div.style.display == "block") ? "none" : "block";
}
</script>
<input type="button" name="rules" value="How to Play!" onclick="toggleDiv()" />
<div id="howto" style="display:none;" class="rules" > WELCOME</div>