使用Javascript / Jquery函数更改DIV显示值

时间:2015-07-24 01:14:24

标签: javascript html function

更新:修复并正常工作。谢谢大家的帮助。

你好我正在制作一个javascript / jQuery按钮,点击它时会显示一个Div(显示:inline-block),当它再次点击时,Div会返回显示:none。理想情况下,我想为动作制作动画,但我真的只想让它先工作。

我的按钮......

Visibility.Visible

我的功能(更新)......

Dim C As Range
Dim GageNum As String
Dim reading As String
Dim MyString As String
Dim Stringlen As Single
Dim location As Single
Dim GLOC As Single
Dim Count As Single
Dim Answer As Integer
Dim Count1 As Single
Dim i As Single

MyString = Range("F2").value 'identifies that cell data in F2 as a string variable
location = InStr(MyString, ",") + 1 'finds the comma separator and adds one to not include comma
GLOC = InStr(MyString, ",") - 1 'finds the location of the comma and goes back one to get rid of the comma.
'MsgBox location 'tests to see what character it is starting at
Stringlen = Len(MyString) - location + 1 'creates a new string that has the length of remaining characters
reading = Mid(MyString, location, Stringlen) 'reads string after the comma until the end of the string
'MsgBox Reading 'test to see if it gets the correct reading from gauage

GageNum = Left(MyString, GLOC) 'finds the gauge number by searching left of the comma
'MsgBox GageNum 'test of the guage number
Set C = .Find(GageNum, LookIn:=xlValues)
If Not C Is Nothing Then
    Dim FirstAddress As String
    Dim Rslt As String
    FirstAddress = C.Address
    Do
        Rslt = Rslt & C.Address & ","
       Set C = .FindNext(C)
Loop While C.Address <> FirstAddress
    'MsgBox Left(Rslt, Len(Rslt) - 1)
    End If
    End With

If Len(C.Offset(, 4)) = 0 Then
    Range("F2").Select
    C.Offset(, 4) = reading 'populates the cell with the reading.

Else
    Answer = MsgBox("Error: Gauge " & C & " measurement has already been taken." & vbNewLine & "Do you want to use this new measurement instead?", vbYesNo + vbQuestion, "Re-measure?")
        If Answer = vbYes Then
            Range("F2").Select
            C.Offset(, 4) = reading 'populates the cell with the reading.
        Else
            'do nothing
        End If
End If

flexMenu的CSS ...

 <button> Menu Test </button>

我真的只是想知道如何获取ID的显示属性并进行更改。我在使用CSS缓出之前完成了悬停功能,以便在悬停时使div增大,并使用$(this).toggleClass(nameOfClass)更改类,但我从未尝试过只更改元素。像这样的其他问题并不适合改变显示值。谢谢你的帮助。

2 个答案:

答案 0 :(得分:1)

你应该使用jquery:

$("button").click(function(){
    $("#flexMenu").toggle();
});

答案 1 :(得分:1)

使用jQuery .on()方法更新,该方法允许您将特定事件绑定到该按钮(事件侦听器)。

$("button").on('click', function () {
    $('#flexMenu').toggle("slow");
});

Fiddle