有没有办法显示/使用用户输入来执行各种功能,例如创建表
Is there a way to display/use the user input to perform various functions like creating a table
我对编程很陌生,我试图创建一个可以根据用户偏好定制的图像。我想出了如何获取输入,但我不知道如何提取/使用它。在下面的代码中,我尝试显示输入,但无法显示。
<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=''),因为当您加载页面时,默认情况下它是空的。
现在只需在顶部输入字段中写一些内容,然后按"单击我!"按钮。
我希望这对您有所帮助。
相关文章:
- 如何使用Java脚本创建提交按钮's的拖放功能
- 使用Jquery创建一个具有单击和悬停功能的菜单
- 创建缩放功能当我们点击签署整个页面获得缩放,当我们点击-签署它获得缩小
- .on(“单击”,..)不处理使用相同的单击功能创建的对象
- 我使用什么语言来创建像Webly这样的拖放功能
- 在Google AdWords中创建可重用功能
- 有没有一种方法可以修改在使用javascript的媒体功能的媒体查询下创建的样式
- 创建具有点击幻灯片功能的 jQuery 滑块
- 如何创建一个脚本,该脚本给定网站列表,它使用其搜索功能来获取信息
- 创建具有蓝鸟承诺的节流功能
- Javascript在不同的功能中创建Cookie
- 具有动态幻灯片创建功能的JavaScript滑块
- 按钮创建无法定位功能代码错误
- 从文件目录结构创建JSON数据的有效功能
- 如何创建具有合并和调整大小功能的表
- 在PhpStorm中创建自定义语言,扩展所有html语言功能
- 创建通用控制器功能
- 创建可在任何地方使用的 JS 函数?范围和功能“未定义”的问题
- 创建高图表点击功能时丢失了 Angularjs 范围
- 如何在WinJS中为列表视图创建排序功能