Home > Article > Web Front-end > 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!