Javascript - 将一些HTML放入文档中

时间:2015-04-27 11:13:53

标签: javascript html if-statement document

我是Javascript初学者。

我尝试将这两个html放入标记中。锚点' ID从tab-1设置为tab-6。

这是我到目前为止所写的内容。它没有做任何事情。有人有想法吗?

Private Sub ReMatrixM2()
    Dim arrInput() As Variant

    Dim Ones() As Integer 'An array keeping indexes of columns which iclude 1.
    Dim iOnes As Integer
    Dim RowM As Integer, ColM As Integer, iRowA As Integer, iColA As Integer

    Dim shtM As Worksheet, shtM2 As Worksheet, cell As Variant

    '1. Take the values included in the sheet in an array
    Set shtM = Worksheets("Sheet3")
    arrInput = shtM.Range("B2").Resize(1066, 592)

    '2. We find columns which includes 1s
    '3. We will use this column indexes by binary combinations to fint the coordinates where 1s are to be added.

    'Now we cycle all rows of array
    For RowM = 1 To 1066 'Rows

        ReDim Ones(0)
        iOnes = 0

        'Now we cycle all colums for each row of array
        For ColM = 1 To 592 'Columns

            If arrInput(RowM, ColM) > 0 Then 'See the difference
                iOnes = iOnes + 1
                ReDim Preserve Ones(iOnes)
                Ones(iOnes) = ColM 'We are taking indexes of columns which includes one.
            Else
               arrInput(RowM, ColM) = 0
            End If

        Next

        If UBound(Ones) > 0 Then

            'For every row of arrInput add the values in -say- cells of Matrix A to arrInput.
            For iRowA = 1 To UBound(Ones)
                For iColA = 1 To UBound(Ones)
                    arrInput(Ones(iRowA), Ones(iColA)) = arrInput(Ones(iRowA), Ones(iColA)) + 1
                Next
            Next

        End If

    Next

    Set shtM2 = Worksheets("Sheet2")
    'We reflect the arrInput to the sheet (Matrix M) at the end.
    shtM2.Range("B2").Resize(1066, 592) = arrInput

End Sub

2 个答案:

答案 0 :(得分:1)

您的代码中存在一些错误:

  1. 如果表达。您需要分离所有表达式并检查您想要的内容。
  2. 您不能在没有符号" +"的情况下分隔该行。或者一切都在同一行。
  3. 引号内引号。或者使用'""',"''",或使用\' = quote
  4. 尝试使用它:

    if (window.location.hash == "#tab-1" || window.location.hash == "#tab-2"
     || window.location.hash == "#tab-3" || window.location.hash == "#tab-4" 
     || window.location.hash == "#tab-5" || window.location.hash == "#tab-6"
    ) {
     // Some code 
    } else { document.write('<div id="tagline">' +
                                '<p id="quote">"Play for fun or dont play at all!"</p>' +
                                '<p id="namer">- S. Pussehl</p> </div>'
               ); 
        } 
    

答案 1 :(得分:0)

您使用双引号包装HTML并使用双引号将id赋予您的元素,以便它不会起作用。

您应该在JavaScript中学习字符串连接。

您的JavaScript应该如下所示。

document.write('<div id="tagline"> <p id="quote">"Play for fun or don\'t play at all!"</p> <p id="namer">- S. Pussehl</p> </div>');

更新: 在if条件下,您应该将window.location.hash与所有内容进行单独比较。