我使用html和javascript製作表單。但是當我點擊輸入文字時,我想改變焦點。我有建立一個功能,但我怎樣才能使這個功能全球,以將其用於其它輸入文字......不是建立每個輸入文字的功能..不同參數的調用函數
我的功能是這樣的:
function changefocus() {
var pass = document.getElementById('pass_id');
if (pass.value == 'Password'){
pass.value = '';
pass.style.color='#000'
}}
和HTML的部分是這樣的:
<input type="text" id="pass_id" name="pass" value="Password" required="required"
onfocus="changefocus()">
我試圖解決我的proble這樣的,但這並不功能... 我給的參數,我的功能
function changefocus(a) {
var pass = document.getElementById('a');
if (pass.value == 'Password'){
pass.value = '';
pass.style.color='#000'
}}
,然後我改變像下面的HTML部分:
<input type="text" id="pass_id" name="pass" value="Password" required="required"
onfocus="changefocus(pass_id)">
能否請你幫我...我該如何解決這個問題?在此先感謝
現在我想,當我離開輸入文本沒有任何書面方式......我想使用的onchange()像下面輸入文本不爲空,但它的功能:
function fillemptyform(pass2) {
if (pass2.value.length==0){
pass2.value = 'Password';
pass2.style.color='#000';
}}
<input type="text" id="pass_id" name="pass" value="Password" required="required"
onfocus="changefocus(this)" onchange="fillemptyform(this)">
我該怎麼做?
它看起來就像你正在實施的佔位符。你爲什麼不使用HTML5的'placeholder'屬性? – Barmar