单击另一个表时,使一个表行消失

时间:2017-02-17 10:01:06

标签: javascript html css html5 css3

我实际上想要做一些事情,我找不到任何类似的javascript而不是jQuery Updated fiddle with working code。感谢LuudJacobs 我知道,这很愚蠢......这只是为了练习,我是新手。它还没有完成 所以,我想做的是:
- 如果“Primo Victoria”行已打开,请在“Attero Dominatus”或任何其他行单击/打开时将其关闭。但是应该允许Show歌词按用户的需要打开多个实例 - 单击时,将“显示歌词”文本变为“隐藏歌词” 我实际上几乎得到了这个,但我没有改变文字,而是建立了一个新链接......

public async override OnAppearing()
{
  var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
  // ...
}    

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

不是直接更改表格行的样式,而是使用类并切换它们。这样,定位“扩展”表行更容易。您的代码可能如下所示:

/* CSS */
.showLyrics{
  display: none; /* hide table row by default */
}
.showLyrics.visible{
  display: table-row; /* show the table row */
}

现在您可以使用Javascript在类之间切换:

//Javascript
document.getElementsByClassName("lyrics")[0].onclick = function(){
  var x = document.getElementsByClassName("showLyrics")[0];

  //check if the row already has a .visible class
  if(x.classList.contains('visible')){

    //hide the row if it's already visible
    x.classList.remove('visible');

    /* other stuff you want to do on hiding a table row */

  }else{

    //hide all rows which are visible (have class .visible)
    var visibleRows = document.querySelectorAll('.visible'),
        i, l = visibleRows.length;

    for(i = 0; i < l; ++i){
      visibleRows[i].classList.remove('visible');
    }

    //show the row
    x.classList.add('visible');

    /* other stuff you want to do on showing a table row */

  }
}

或者,您可以x.classList.toggle('visible');使用.classListMDN上阅读<tr class="tableEntry1, hover">

作为旁注:当我看着你的小提琴时,我把目光投向了这个:<tr class="tableEntry1 hover">。我很确定你的意思是 Public Class frmSelect Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ds As New DataSet Dim da As Odbc.OdbcDataAdapter = New Odbc.OdbcDataAdapter("SELECT tblStudInfo.LastName AS myName, tblAddress.Address AS myAddress, tblCourses.CourseName AS myCourse FROM tblStudInfo INNER JOIN tblAddress ON tblStudInfo.AddressID = tblAddress.AddressID INNER JOIN tblCourses ON tblStudInfo.CourseCode = tblCourses.CourseCode WHERE tblStudInfo.StudID = '01-2016-003'", mConnection.myConn) da.Fill(ds, "tblStudInfo") Me.TextBox1.Text = ds.Tables("tblStudInfo").Rows(0)("myName").ToString Me.TextBox2.Text = ds.Tables("tblStudInfo").Rows(0)("myAddress").ToString Me.TextBox3.Text = ds.Tables("tblStudInfo").Rows(0)("myCourse").ToString End Sub End Class 。注意:没有逗号。类应该用空格分隔,而不是用逗号分隔。