Home > Web Front-end > HTML Tutorial > What are the ways to get the value of javascript variable in html

What are the ways to get the value of javascript variable in html

王林
Release: 2020-12-03 15:28:26
forward
7776 people have browsed it

What are the ways to get the value of javascript variable in html

htmlThere are three ways to obtain the value of javascript variables:

(Free learning video sharing: html video tutorial)

Method 1: Embed into html sentences, when html elements use

<scriptlanguage="javascript"type="text/javascript">
   var df=newDate(); 
   var year= df.getFullYear() ;
   document.write("<td>"+year+" J2EE开发</td>");
</script>
Copy after login

Method 2: Use jquery

js part:

$(function(){
      vardf=newDate();
      varyear=df.getFullYear()
      $("#td1").text(year+" J2EE开发");
   });
Copy after login

html:

<td id="td1"></td>
Copy after login

Method 3: Use jsp syntax

<%
   java.text.SimpleDateFormatdf = new java.text.SimpleDateFormat("yyyy");
   Stringyear = df.format(new java.util.Date());
 %>
 
<td align="center"><%=year%> J2EE开发</font></td></tr>
Copy after login

Related recommendations:html tutorial

The above is the detailed content of What are the ways to get the value of javascript variable in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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