如何通过id编写增量文档get元素

时间:2016-10-12 16:13:20

标签: javascript jquery html

function validasiForm(){
    var y = document.getElementsByName('merk[]').length;
    console.log(y);
    for (var i = 0; i < y ; i++) {
        var merk = document.getElementsByName('merk[]')[i].value;
        if (merk == null || merk == "") {
        document.getElementById("i").innerHTML="<p class='color-red'>*validation message</p>";
        // document.getElementById("merk2").innerHTML="<p class='color-red'>*nama merk harus di isi</p>";
          return false;
      }
    }
  }

**高于我的html代码,当我点击添加行时会添加id =“2”的新行** 这是我的javascript代码

{{1}}

所以我的问题是如何用id动态显示带动态get元素的验证消息?

1 个答案:

答案 0 :(得分:0)

int确实在寻找ID为“i”的元素。使用不同的命名约定,如“elem1”或其他东西。然后是 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ' Parsing using a delimeter Dim text1() As Byte = Encoding.UTF8.GetBytes("stackoverflow" & "-") ' concatenate a delimter in the string ' Convert to string, otherwise the program sends the byte value of 13 plus 3 padded zeros so you end up transmitting a Carriage return and 3 null characters Dim len1() As Byte = Encoding.UTF8.GetBytes(text1.Length - 1.ToString) ' Subtract the delimteter character value from the total Dim byteLen As Integer = text1.Length + len1.Length Dim bStream(byteLen) As Byte text1.CopyTo(bStream, 0) len1.CopyTo(bStream, text1.Length) ' This goes in the other program Dim Str() As String = Encoding.UTF8.GetString(bStream, 0, bStream.Length).Split("-") Dim Text As String = Str(0) Dim Index As Integer = CInt(Str(1)) End Sub

值得一提的是,无论如何,ID不应以数字开头。这将导致错误作为javascript中的变量名(ID是隐式全局变量),CSS将忽略它。它可能永远不会让你痛苦,但嘿 - 很高兴知道。