如何从html标签将数据临时存储在java脚本中
How to store data temporarily in java script from a html tag?
我是JavaScript的新手,这里有一个我不知道如何克服的挑战!
这是我尝试过的示例代码:
<body>
<p id="hello">Hello world.</p>
<script type="text/javascript">
var store,newString,finalString;
//i want to store the content of <p> tag in store variable
store=?
newString="I am Shuvrow";
finalString = store + newString;
//finally i want to replace the content of <p> tag by finalString variable
</script>
</body>
感谢
使用文档元素的innerHTML
属性,例如:
<body>
<p id="hello">Hello world.</p>
<script type="text/javascript">
var store,newString,finalString;
// Get the contents of the element with the ID of 'hello' and assign it to the store variable.
store = document.getElementById('hello').innerHTML;
newString="I am Shuvrow";
finalString = store + newString;
// Replace the contents of the element with the ID of 'hello' with the value of the finalString variable.
document.getElementById('hello').innerHTML = finalString;
</script>
</body>
相关文章:
- 如何在Java Script中比较二维数组和一维数组,并将常见数据存储在另一个数组中
- 在使用java使用dropbox选择器从dropbox中提取文件后,如何将文件存储在服务器中
- 如何使用java脚本更改浏览器的内存管理以增加会话存储和本地存储的内存
- 在 Java 中使用 IE/Chrome HTML 渲染器或使用 JavaScript 存储文件
- Java Selenium,在javascript激活后存储更新的页面源代码
- Glassfish/Java/JS:将图像文件存储到servlet中,并将其检索到网页中
- 在java web应用程序中存储UI配置的位置,并从jsp页面读写配置文件
- 如何从html标签将数据临时存储在java脚本中
- Java和JS:将结果存储为Java变量
- 我正在尝试使用java脚本存储click事件上的列表项,并将其访问到另一个页面进行sql查询,但我做不到
- Java -如何使用gson库解析json响应+存储会话id,以便它可以被gae中的javascript函数访问
- 网站使用facebooklogin插件并将用户的凭据存储到数据库的JAVA或Javascript的文本框中
- 如何使用html和java脚本在windows azure移动服务中存储文件(简历)
- 如何在java脚本函数的Spring消息标记中存储var的值
- 通过java脚本存储表单变量
- 使用Java脚本向服务器发送表单数据并将其存储在服务器中
- Java脚本使用数组来存储条件
- 在Java的Spring框架中,将.properties文件中定义的元素存储到JavaScript变量中的最佳方法是什么
- 在jspString变量中存储一个java脚本值
- 存储我的Java函数返回String In JavaScript变量的值