如何解决即使未选中,脚本也会继续保存值
我希望脚本仅在选中文本时保存文本的值。 如果可能的话,我还想仅在单击它时将其值保存为变量,因此例如 名称:{此处为变量}#如果选中
<html>
<head>
<title>Feedback</title>
<script language="Javascript" >
function download(filename,text) {
var pom = document.createElement('a');
pom.setAttribute('href','data:text/plain;charset=utf-8,' +
encodeURIComponent(text));
pom.setAttribute('download',filename);
pom.style.display = 'none';
document.body.appendChild(pom);
pom.click();
document.body.removeChild(pom);
}
function addTextHTML()
{
document.addtext.name.value = document.addtext.name.value + ".html"
}
function addTextTXT()
{
document.addtext.name.value = document.addtext.name.value + ".txt"
}
</script>
</head>
<body>
<form name="addtext" onsubmit="download(this['name'].value,this['text'].value)">
<input type="checkBox" name="text" id="test" value=name>
<label for="test">Test</label>
<br>
<input type="text" name="name" value="" placeholder="File Name">
<input type="submit" onClick="addTextHTML();" value="Save As HTML">
<input type="submit" onClick="addTexttxt();" value="Save As TXT">
</form>
</body>
</html>
解决方法
尝试使用break;
。但是它将给出错误,您将可以在控制台上看到它。
所以尝试这样的事情;
var text = "";
var a;
for (a = 1; a < 2; a++){
//code will be here which gets in the loop
text += "Working";
}
document.getElementById("demo").innerHTML = text;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width = device-width,initial-scale = 1.0">
<meta http-equiv="X-UA-Compatible" content = "ie=edge">
<title> Keat </title>
</head>
<body>
<p id="demo"></p>
</body>
</html>
这将使循环进行,但会限制循环。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。