例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>dance styles</title> </head> <body> <div > <p> Dance Styles (choose) <input type="text" name="Dance Styles" id="DanceStyles" style="width:255px;" /></p> <div class="choose"> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer;">Ballet</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Contemporar</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Jazz</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Street Jazz</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Hip Hop</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Tap</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Ballroom</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Latin</a></p> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer">Belly</a></p> </div> </div> </body> </html>
以上這個采用了innerText來獲取文字的代碼,在火狐中是失效的。
但是如果加上一段JavaScript:
<script type="text/javascript"> function innerText(node){//返回的是數組類型 var innerTextArr = []; var root = document.getElementById(node); var getChild = function(node){ var childs = node.childNodes; for(var i=0;i<childs.length;i++) if(childs[i].nodeType == 3) innerTextArr.push(childs[i].nodeValue); else if(childs[i].nodeType == 1){ getChild(childs[i]); } } getChild(root); return innerTextArr; } </script>
就使得innerText也起作用了。
還有一個同樣功效用來支持outerHTML的JS函數:

function outerHTML(node){//返回的是字符串類型 var tag = document.getElementById(node).tagName; var outerHTMLStr = "<" + tag.toLowerCase(); var atts = document.getElementById(node).attributes; for(var i = 0;i<atts.length;i++) outerHTMLStr += " " + atts[i].name + "=\"" + atts[i].value + "\""; outerHTMLStr += ">"; outerHTMLStr += document.getElementById(node).innerHTML; outerHTMLStr += "<" + tag.toLowerCase() + ">" return outerHTMLStr; }
否則的話,只要把所有的innerText都換成innerHTML就可以直接讓火狐支持,而不需要額外的函數。
像這樣:
<div > <p> Dance Styles (choose) <input type="text" name="Dance Styles" id="DanceStyles" style="width:255px;" /></p> <div class="choose"> <p><a onclick= "DanceStyles.value=innerText " style=" cursor:pointer;">Ballet</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Contemporar</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Jazz</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Street Jazz</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Hip Hop</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Tap</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Ballroom</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Latin</a></p> <p><a onclick= "DanceStyles.value=innerHTML " style=" cursor:pointer">Belly</a></p> </div> </div>