[英]On click of button reload page and change button text
I'd like to have a click on a button reload the page and change the text inside the button. 我想单击一个按钮,以重新加载页面并更改按钮内的文本。
For reload I got: 对于重新加载,我得到了:
Javascript: Javascript:
function reloadPage(){
window.parent.location = window.parent.location.href;}
HTML: HTML:
<button type="button" onClick="reloadPage()">Start</button>
<script src="reloadpage.js"></script>
After click, the text in the button must change from "Start" to "Try Again!" 单击后,按钮中的文本必须从“开始”更改为“再试一次!”。
How can I do this? 我怎样才能做到这一点?
Thank you. 谢谢。
You could do this by adding a query string on reload, and then have a script that detects the query string and changes the text of the button onload. 您可以通过在重新加载时添加查询字符串来做到这一点,然后使用一个脚本来检测查询字符串并更改按钮加载时的文本。
JavaScript: JavaScript:
function reloadPage(){
window.parent.location = window.parent.location.href+"reload=true";}
function checkQString(){
// get query strings and store reload qstring in variable
if (reload) {
document.getElementById('btn').innerHTML = 'Try Again!';
}
HTML 的HTML
<button id='btn' type="button" onLoad='checkQString();' onClick="reloadPage()">Start</button>
<script src="reloadpage.js"></script>
You can use Cookies. 您可以使用Cookies。 With js you can use https://plugins.jquery.com/cookie/ Or can use server side cookies
使用js,您可以使用https://plugins.jquery.com/cookie/,也可以使用服务器端Cookie
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.