HTML获取输入值

时间:2016-10-16 01:06:32

标签: html input

我正在尝试创建一个链接,并在URL中放置一个变量,如下所示:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <a href="index.html?color=">Main Page</a>
  <input type="color" id="colorPicker" value="#808080">
</body>
<html>

我正在尝试将用户发送到index.html?color=VALUE GOES HERE。而不是VALUE GOES HERE,我想要当前的颜色输入值。

2 个答案:

答案 0 :(得分:2)

您可以使用表单

  

method属性指定如何发送表单数据(表单数据是   发送到action属性中指定的页面。

     

表单数据可以作为URL变量发送(方法=&#34; get&#34;)

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title> Atlantic Trails Resort</title>
    <link rel="stylesheet" href="atlantic.css" type="text/css">
    <style type="text/css">

<!--
body{background-color: #FFFFFF;color: #666666; font-family: Helvetica;}

header{background-color: #000033; color: #FFFFFF; line-height: 400%; text-indent: 1em; 
background-image: url("sunset.jpg");background-position: right;}

nav{background-color: #90C7E3;}

h2{color: #3399CC;}

h3{color: #000033;}

resort{color: #5C7FA3;}
    -->
    </style>
</head>

<body>
    <!-- page content goes here -->

    <div id ="wrapper">
        <header>
            <h1>Atlantic Trails Resort</h1>
        </header>

        <nav>

            <a href="Index.html">Home</a>&nbsp;
            <a href="Accommodations.html">Accommodations</a>&nbsp;
            <a href="Activities.html">Activities</a>&nbsp;
            <a href="Reservations.html">Reservations</a>&nbsp;

        </nav>

            <h2>Enjoy Nature in Luxury</h2>
            <img src="coast.jpg" alt height="250" width="320">
            <p><span class ="resort">Atlantic Trails Resort</span> offers a special lodging experience
            on the rugged Atlantic North Coast of Maine. Relax in serentiy
            with panoramic views of the Atlantic Ocean.</p>

            <ul>
                <li>Private bunglows with decks overlooking the ocean.</li>
                <li>Activities lodge with fireplace and gift shop</li>
                <li>Nightly fine dinning at the Overlook Cafe</li>
                <li>Heated outdoor pool and whirlpool</li>
                <li>Guided hiking tours of the pine forests</li>

            </ul>
            <div><span class ="contact">Atlantic Trails Resort</span></div>
            <div>1210 Atlantic Trails Way</div>
            <div>Cliffside, Maine 04226</div>

            <br>
            <div>888-555-5555</div>
            <br>





<footer>

    Copyright &copy; 2016 Atlantic Trails resort<br>


</footer>
</div>
</body>



</html>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我能想到的唯一方法是使用JavaScript,很抱歉,如果这不是你想要的:

function urlUpdate(hex) {
  document.getElementById("link").href = "index.html?color=" + hex;
}
<!DOCTYPE html>
<html>

<head>
</head>

<body>
  <a id='link' href="index.html?color=">Main Page</a>
  <input type="color" id="colorPicker" value="#808080" onchange="urlUpdate(value)">
</body>
<html>