2013-10-04 88 views
1

相呼應的HTML頁面信息,我有以下腳本打印或從JavaScript

function validateEmailp() { 
var messagemail = document.getElementById('emailerrorz').innerText; 
var two = document.getElementById('email').value; 
var first = two.split("@")[1]; 
var badEmails = ["gmail.com", "yahoo.com"] 
if (badEmails.indexOf(first) != -1) { 
     document.getElementById("email").value = ""; //this works 
    messagemail = 'We do not accept free e-mails'; //this doesn't 
    return false; 
    } 
return true; 
} 

和HTML

<td>{EMAILFIELD}<span id="emailerrorz"></span></td> 

和{EMAILFIELD}在PHP

<input id="email" class="txt" type="text" name="email" size="25" value="" maxlength="255" onblur="validateEmailp()"></input> 

但它不對於我在打印跨度id中的錯誤時不起作用。它只適用於從那裏重置值。

回答

1

當你做var messagemail = document.getElementById('emailerrorz').innerText;你的變量存儲一個字符串與該內容。

當你var messagemail = document.getElementById('emailerrorz');您的變量存儲對象/元素,然後你可以使用屬性.innerText

所以使用:

var messagemail = document.getElementById('emailerrorz'); 
// rest of code 
messagemail.innerText = 'We do not accept free e-mails';