Dieser Artikel beschreibt die Verwendung von Split und Ersatz in JS. Teilen Sie es für Ihre Referenz. Die spezifische Analyse ist wie folgt:
1.. Split:
Kopieren Sie den Code wie folgt: <html>
<kopf>
<title>
Registrierungsliste für Weiterbildung für Praktiker-PRINT-Check-in-Formular SDFSD </tr> <tr> </tr> SDFSD
</title>
</head>
<body>
<script type = "text/javaScript">
var str = "1231 <tr id =/" 123/"> SDFSD </tr> <tr> </tr>";
Alarm (str);
var lst1 = str.split ("<tr id =/" 123/">");
Alarm (LST1 [1]);
var lst2 = lst1 [1] .Split ("</tr>");
Alert (lst2 [0]);
var str2 = "";
für (var i = 1; i <lst2.Length; i ++)
{
if (i == 1)
str2 += lst2 [i];
anders
str2 + = "</tr>" + lst2 [i];
}
Alarm (str2);
var Streturn = lst1 [0] + "<kopf> <tr id =/" 123/">" + lst2 [0] + "</tr> </head>" + str2;
Alarm (Streturn);
</script>
</body>
</html>
2. Ersetzen
Die Codekopie lautet wie folgt: strhtml = strhtml.replace ("<tr class = gridView_header align = Middle>", "<thead> <tr class = gridView_header align = Middle>");
strhtml = strhtml.replace ("</tr>", "</tr> </thead>");
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.