2016-12-08 9 views
-2

スタイルのpge [1]はどのようにすればいいですか?その段落全体を特定の色にしたい。スタイリングされる配列値にIDまたはクラスを追加する方法はありますか?スタイリングJavascriptの配列

function myPar() { 

pge = new Array() 

pge[4] = "So have you reverse engineered this document?" 

pge[3] = "This first instance a button creation will create multiple buttons with no purpose. They will not be linked to any site in this lecture video. The first need to become familiar with the process and with the required syntax for setting a series of attributes. When the button construction sequence is completed the process will then append the button to the body tag as it did for the paragraph tag." 

pge[2] = "The same process that was used to create paragraphs dynamically will be used to create buttons dynamically. This first instance of button creation will be design to create a button each time the function trigger is pressed." 

pge[5] = "So this build of page content can happen in any sequence that is seen fit and then modified by changing index vaues." 

pge[0] = "It was the best of times, it was the worst of times" 

pge[1]= "There's no way that we can work out a way to colonize Mars in the next 50 years. Think of the logistical obstacles to such a plan. You'd need food, water, medicine. You'd need engineers, doctors, nurses, endless oxygen, of which mars has none." 

pge[6] = "So what is such a big deal here?" 


for (i=0;i<=pge.length-1;i++) { 

var pgp = document.createElement("p"); 

var txt = document.createTextNode(pge[i]); 


pgp.appendChild(txt); 
pgp.setAttribute("class","mine"); 

pgp.appendChild(document.createElement("br")); 

pgp.setAttribute("style","color:#605;font-size:1.5em;") 

document.body.appendChild(pgp); 
txt = ""; 


} 


} 

HTMLので、少し混乱....私はouroborusによって与えられたとして、文字列内のHTMLを埋め込むことを試みたが、それが動作していないようでした...私はJSにスーパー新たなんです...

<html> 
<head> 
<meta charset="UTF-8"> 
<title>Untitled Document</title> 
</head> 
<style> 







.mine::first-letter { 

    color:blue; 

    font-size:2em;} 




</style> 



<body> 



<p>Click the button to create a paragraph and add text at the same time.</p> 


<button onclick="myPar()">Write a paragraph</button> 



<script src="JS/thePars.js"> 





</script> 

</body> 
</html> 
+0

。 JavaScript文字列には色がありません。 – Oriol

+0

こんにちはOriol、私は、配列を表示するボタンをセットアップしている、私は何をしたいのは、段落の残りの部分とは別の色を作ることです..... – hendro3

+0

私はそこに残りの助けになるより多くのコードが疑わしい私たちのあなたの質問を理解する。また、あなたは努力することが期待されます。あなたは何を試しましたか? – Ouroborus

答えて

0

文字列にHTMLを埋め込み、文字列をドキュメントに挿入するときに考慮する必要があります。例えば

:私は理解していない

var str = '<span class="colormered">So... How about that sportsing?</span>'; 
 

 
document.getElementsByTagName('P')[0].innerHTML = str;
.colormered { 
 
    color:red; 
 
}
<p></p>

+2

ダウンボートは単独で建設的ではありません。 – Ouroborus