English 中文(简体)
彩色皮条
原标题:color picker code

I have this code to change the color of elements like the Background-color,text color,active link color,visited link color etc. inside a div. I have to enter the color for each in the text-boxes and accordingly the color of background,text color,link colors would change. This is the program objective. But I can t change the colors of the active, followed and visited links. How to do that with only HTML, CSS and JavaScript? Please don t tell me any method using jQuery, as I don t know jQuery. I only want it it with JavaScript.

 <html>
     <head>
     </head>
     <body>
         <script>
             function fun()
             {
                 var bg=document.getElementById("t1").value;
                 var txt=document.getElementById("t2").value;
                 var al=document.getElementById("t3").value;
                 var vl=document.getElementById("t4").value;
                 var hv=document.getElementById("t5").value;
                 document.getElementById("dv").style.backgroundColor=bg;
                 document.getElementById("dv").style.alinkcolor=txt;
                 document.getElementById("dv").style.vlinkcolor=al;
                 document.getElementById("dv").style.color=vl;
                 document.getElementById("dv").style.color=hv;
             }
         </script>
         <h1>Enter Colors: </h1>
         Background: <input type="text" id="t1" name="txt1">
         <br/><br/>
         Text:  <input type="text" id="t2" name="txt2">
         <br/><br/>
         Link:  <input type="text" id="t3" name="link">
         <br/><br/>
         Active Link: <input type="text" id="t4" name="alink">
         <br/><br/>
         Followed Link: <input type="text" id="t5" name="vlink">
         <br/><br/>
         <input type="button" value="test" onclick="fun();">
         <br/><br/>
         <div id="dv">&nbsp;hello
             This is a Test<br/>
             You Have Selected These Colors<br/>
             <a href="#">This is a Test Link</a><br/>
         </div>
 </body>
 </html>
问题回答

页: 1 更新了你的代码,将IDs分配给这些要素。 这里是最新的法典。 询问该法典是否有助于。 感谢。

<html>
<head>
</head>
<body>
     <script>
         function fun()
         {
             var bg=document.getElementById("t1").value;
             var txt=document.getElementById("t2").value;
             var al=document.getElementById("t3").value;
             var vl=document.getElementById("t4").value;
             var hv=document.getElementById("t5").value;
             document.getElementById("dv").style.backgroundColor=bg;
             document.getElementById("link").style.alinkcolor=al;
             document.getElementById("link").style.vlinkcolor=vl;
             document.getElementById("para").style.color=txt;
             document.getElementById("link").style.color=hv;
         }
     </script>
     <h1>Enter Colors: </h1>
     Background: <input type="text" id="t1" name="txt1">
     <br/><br/>
     Text:  <input type="text" id="t2" name="txt2">
     <br/><br/>
     Link:  <input type="text" id="t3" name="link">
     <br/><br/>
     Active Link: <input type="text" id="t4" name="alink">
     <br/><br/>
     Followed Link: <input type="text" id="t5" name="vlink">
     <br/><br/>
     <input type="button" value="test" onclick="fun();">
     <br/><br/>
     <div id="dv">&nbsp;
       <p id="para">hello This is a Test<br/>
         You Have Selected These Colors<br/><p>
         <a id="link" href="#">This is a Test Link</a><br/>
     </div>





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签