2 回答
TA贡献1852条经验 获得超7个赞
.getAttribute("value")
value属性保存元素的默认值。
当前值(即用户输入的值)保存在 value属性中。
使用.value
。
TA贡献1840条经验 获得超5个赞
每个输入都需要不同的 ID(和名称)。
您还需要将 .getAttribute("value") 替换为 .value
以下代码有效:
<form class="contact100-form validate-form">
<div id="source">
<div class="wrap-input100 validate-input" required="required">
<span class="label-input100"><h4>Name</h4></span>
<input id="name" class="input100" type="text" name="name" placeholder="enter your full name..." />
</div>
<div class="wrap-input100 validate-input" required="required">
<span class="label-input100"><h4>Your Birthday</h4></span>
<input id="birthday" class="input100" type="text" name="birthday" placeholder="write your complete DOB dd-mm-yyyy..." />
</div>
<div class="wrap-input100 validate-input" required="required">
<span class="label-input100"><h4>Contact Number (Primary)</h4></span>
<input id="contactNb" class="input100" type="text" name="contactNb" placeholder="this is most important..." />
</div>
<div class="container-contact100-form-btn">
<div class="wrap-contact100-form-btn">
<div class="contact100-form-bgbtn"></div>
<button type="button" id="save" title="Save as text file">Send</button>
</div>
</div>
</div>
</form>
<script type="text/javascript">
document.getElementById("save").onclick = function () {
var name = document.getElementById('name').value;
var birthday = document.getElementById('birthday').value;
var contactNb = document.getElementById('contactNb').value;
var content = " name: " + name + "\n birthday: " + birthday + "\n contact number: " + contactNb
window.open( "data:application/txt," + encodeURIComponent(content), "f.txt" );
};
</script>
- 2 回答
- 0 关注
- 110 浏览
添加回答
举报