2016-09-03 71 views
1

我試圖&放解碼回&,我已經用下面方法,請,哪裏是我的錯誤試過嗎?解碼&在附加JavaScript網址

方法嘗試: Replace & to &

我的代碼:

讓我們來看看這些代碼工作的正確方法現在
<style> 
.mistake { 
    color: red; 
} 
.mistake2 { 
color: red; 
} 
</style> 

<script type="text/JavaScript"> 
var main = document.getElementById("test").innerHTML; 
function mobitransact(text) { 
var words = text.split(" ");  
for (var i = 0; i < words.length; ++i) 
{ 
// Pull the word from our array. 
var word = words[i]; 
if (i == 7) // spellcheck logic here. 
{ 
    // Push this content to the array. 
var n = word; 


} 
} var words2 = text.split(" "); 

// Loop through the sentences. 
for (var j = 0; j < words2.length; ++j) 
{ 
// Pull the word from our array. 
var word2 = words2[j]; 
if (j == 4) // spellcheck logic here. 
{ 
var m = word2; 
} } 
var a = document.createElement('a'); 
var linkText = document.createTextNode("VALIDATE PAYMENT if not auto redirected"); 
a.appendChild(linkText); 
a.title = "mistake2"; 
a.class = "mistake"; 
a.href = "http://facebook.mobi/site_2.html?me=" + m + "&amp;my=" + n + ""; 
var div = document.createElement('div'); 
div.innerHTML = a 
var decoded = div.firstChild.nodeValue; 

document.body.appendChild(a); 

} 
mobitransact(main); 
</script> 
+1

爲什麼HTML編碼出現在URL擺在首位? –

回答

0

請試試這個:

我已經添加了一個decodeHtml函數。這將解碼您的a.href

function decodeHtml(html) { 
 
    var txt = document.createElement("textarea"); 
 
    txt.innerHTML = html; 
 
    return txt.value; 
 
} 
 

 
var main = document.getElementById("test").innerHTML; 
 
function jivetransact(text) { 
 
var words = text.split(" ");  
 
for (var i = 0; i < words.length; ++i) 
 
{ 
 
// Pull the word from our array. 
 
var word = words[i]; 
 
if (i == 7) // spellcheck logic here. 
 
{ 
 
    // Push this content to the array. 
 
var n = word; 
 

 

 
} 
 
} var words2 = text.split(" "); 
 

 
// Loop through the sentences. 
 
for (var j = 0; j < words2.length; ++j) 
 
{ 
 
// Pull the word from our array. 
 
var word2 = words2[j]; 
 
if (j == 4) // spellcheck logic here. 
 
{ 
 
var m = word2; 
 
} } 
 
var a = document.createElement('a'); 
 
var linkText = document.createTextNode("VALIDATE PAYMENT if not auto redirected"); 
 
a.appendChild(linkText); 
 
a.title = "mistake2"; 
 
a.class = "mistake"; 
 
a.href = decodeHtml("http://jivetransact.wapka.mobi/site_2.html?me=" + m + "&amp;my=" + n + ""); 
 
document.body.appendChild(a); 
 

 
} 
 
jivetransact(main);
<div id='test'></div>

+0

感謝您的修復,您是一位現場救星! – Reuben

+0

@Reuben非常感謝! –