Home > Web Front-end > JS Tutorial > How to assign value to span tag in javascript_javascript skills

How to assign value to span tag in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:29:34
Original
2406 people have browsed it

How to assign value to span tag in js? There are generally two methods:

The first method: output html

<body onload="s()">
<span id="hello"></span>
<script language="javascript">
 function s(){
document.getElementById("hello").innerHTML = "<iframe src= height=400 width=300></iframe>";
}
 </script>
Copy after login

Second method: output text

<body onload="s()">
<span id="hello"></span>
<script language="javascript">
 function s(){
document.getElementById("hello").innerText = "hello world";
}
</script>
Copy after login

Assign values ​​to multiple spans through jquery after the page is loaded

Since I want to display the current time in several places after the page is loaded, I need to assign values ​​to multiple spans.

The span code is written as follows:

<span name="currentDate"></span> (多个span) 
Copy after login

jQuery writing:

<script> 
$(document).ready(function() { 
var currentDate = new Date().toLocaleDateString(); 
$("span[name='currentDate']").each(function() { 
$(this).text(currentDate); 
}); 
}); 
</script> 
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template