Recientemente escribí otro proyecto y usé InnerHTML, pero descubrí que después de llamar a InnerHTML, OnClick fue invalidado también. Directamente, pero se puede implementar indirectamente.
Ejemplo 1: Este ejemplo está en el cierre que no se puede lograr
Copiar código del código de la siguiente manera:
<html>
<Evista>
<script diferir>
Función inscell (th)
var name = th.name;
var id = th.id;
if (name == "no") {{
id.innerhtml = "<input type = 'button' onClick = 'inscall (this)' valor = 'en línea'
nombre = 'no' id = '1'> "";
} Demás {
id.innerhtml = "<input type = 'button' onClick = 'inscall (this)' value = 'fuera de línea'
name = 'Yes' id = '1'> "" ";
}
</script>
</ablo>
<Body>
<Br />
<span id = "msg">
<input type = "button" onClick = "inscall (this)" value = "fuera de línea" name = "sí" id = "1">
</span>
</body>
</html>
El ejemplo anterior es juzgar si está en línea en función del nombre del botón o fuera de línea ~~~ Encontramos que cuando haga clic en la primera vez, no será válido ~~~~~~
En este momento, podemos realizar el disfraz, como sigue:
Copiar código del código de la siguiente manera:
<html>
<Evista>
<script diferir>
Función inscell (th)
{{
var name = th.name;
var id = th.id;
alerta (nombre+"-"+id);
var span = document.getElementById (id);
if (name == "no") {{
span.innerhtml = "<input type = 'button' value = 'offline'>";
span.name = "Sí";
} Demás {
span.innerhtml = "<input type = 'button' value = 'go online'>";
span.name = "no";
}
}
</script>
</ablo>
<Body>
<Br />
<span id = "1" onClick = "inscell (this)" name = "no">
<input type = "button" value = "en línea">
</span>
</body>
</html>