我在網站上查了一些其他問題,但我仍然處於虧損狀態。我想使用JavaScript(不JQuery的)採取以下形式:更改顯示屬性onfocus/onblur
<!doctype html>
<html>
<head>
<meta charset = "UTF-8"/>
<title>Account Sign-Up</title>
</head>
<body>
<h1>Profile Sign-Up</h1>
<fieldset>
<p>
<p><label for = "first_name">First Name: </label>
<input type = "text" id = "first_name" onfocus = "javascript:showText(1)"/>
<div id = "div1" style = "display:none">Enter your first name</div>
<p><label for = "last_name">Last Name: </label>
<input type = "text" id = "last_name" onfocus = "showText(2)"/>
<div id = "div2" style = "display:none">Enter your last name</div>
<p><label for = "email">E-Mail: </label>
<input type = "text" id = "email" onfocus = "showText(3)"/>
<div id = "div3" style = "display:none">Enter E-Mail</div>
<p><label for = "username">Username: </label>
<input type = "text" id = "username" onfocus = "showText(4)"/>
<div id = "div4" style = "display:none">Enter your desired screen name</div>
<p><label for = "password">Password: </label>
<input type = "password" id = "password" onfocus = "showText(5)"/>
<div id = "div5" style = "display:none">Enter the password you will use to log into your account in the future</div>
<p><label for = "retype_password">Retype your password again: </label>
<input type = "password" id = "retype_password" onfocus = "showText(6)"/>
<div id = "div6" style = "display:none">Type your password again</div>
<p><button name = "submit" type = "button" id = "submit">Submit</button>
</p>
</fieldset>
<script src = "Q10.js"></script>
</body>
</html>
,並應用下面的腳本顯示每當文本框獲得焦點的一些隱藏的文本。我不希望超出所描述的範圍。所以不,我不能在頁腳的單個div元素中使用彈出式工具提示或文本等。我也不關注數據注入或代碼的漏洞/安全性,因爲我沒有使用它來做任何事情實際的。
var enableBtn = function() {
document.getElementById("submit").disabled = false;
};
//function enables submit button
var disableBtn = function() {
document.getElementById("submit").disabled = true;
};
//disables submit button
var checkInput = function() {
if (document.getElementById("password").value.length > 0 && document.getElementById("username").value.length > 0 && document.getElementById("password").value === document.getElementById("retype_password").value) {
enableBtn();
}
else {
disableBtn();
}
};
var showText = function (numb) {
document.getElementById("div" + numb).style = "display:inline";
};
var hideText = function(numb) {
document.getElementById("div" + numb).style = "display:none";
};
document.onfocus = checkInput
//if password and username have an input- and retype password is the same as password, button is usable. If not, it's disabled.
document.getElementById("retype_password").oninput = checkInput;
document.getElementById("password").oninput = checkInput
//document.getElementById("password").onclick = function() {alert(document.getElementById("password").value.length)};
//
目前,我正在運行到一個打嗝,因爲我不能讓事件上運行腳本的重點,不知道還有什麼地方可以轉。請幫助> <
似乎'showText()'函數大幹快上'onfocus'正確調用。看不到'hideText()'函數被調用?這有什麼問題? – Rohit
我在第一個html onfocus調用中做了不同的處理。我想第一個是正確的?但也 - 我從來沒有得到任何顯示正確 - 所以我從來沒有打擾嘗試隱藏工作 – user3734311
你是否在小提琴或任何其他在線編輯器上運行此代碼? – Rohit