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

王林
王林forward
2020-12-03 15:28:267774browse

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>

Method 2: Use jquery

js part:

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

html:

<td id="td1"></td>

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>

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete