有没有办法显示/使用用户输入来执行各种功能,例如创建表

Is there a way to display/use the user input to perform various functions like creating a table

本文关键字:功能 创建 执行 显示 输入 用户 有没有      更新时间:2023-09-26

我对编程很陌生,我试图创建一个可以根据用户偏好定制的图像。我想出了如何获取输入,但我不知道如何提取/使用它。在下面的代码中,我尝试显示输入,但无法显示。

<form>
Title:
<input type="text" input id="title" value=''autofocus> 
<br><br>
Primary Function Color
<input type="color" name="pfColor">
<br><br>
Secondary function Color
<input type="color" name="sfColor">
<br><br>
Neutral Color
<input type="color" name="nColor">
<br><br>
<input type=submit onclick="Initial_Display()"> 
<input type=reset>
</form>
<script>
    function Initial_Display(){
    var Title=document.getElementById("title").innerHTML;
    };
</script>

要帮助您入门,请尝试以下操作:(我已经尽可能少地更改它,足以让您看到一些事情发生)。

<form>
    Title:
    <input type="text" id="title" autofocus> 
    <br><br>
    Primary Function Color
    <input type="color" name="pfColor">
    <br><br>
    Secondary function Color
    <input type="color" name="sfColor">
    <br><br>
    Neutral Color
    <input type="color" name="nColor">
    <br><br>
    <input type="button" onclick="Initial_Display()" value="click me!"> 
    <input type="reset">
</form>
<script>
    function Initial_Display(){
    var Title=document.getElementById("title").value;
    alert(Title);
    };
</script>
1)将"提交"按钮

更改为普通按钮(type="button"),我这样做是因为否则页面被提交并且onclick没有机会做任何事情。

2) var Title=document.getElementById("title").value;- 在这里我更改了它,以便您获得输入的"值",而不是 innerHTML。

3)我在底部的脚本中添加了一个alert(),以便您可以看到我们得到的值。

4)您不需要设置第一个输入字段的值(value=''),因为当您加载页面时,默认情况下它是空的。

现在只需在顶部输入字段中写一些内容,然后按"单击我!"按钮。

我希望这对您有所帮助。