javascript - 将字段值设置为 javascript 变量
问题描述
我有一个名为样式的 html 字段,它从 php 值中获取其值:
<input name="styles" value="'.$colorstyle.'" id="styles" >
现在我有一个 javascript 代码,我需要在其中放置字段的值:
this.colours = {
'normal' : {
'txt' : "rgb(255,255,255)",
'arrow':"rgb(0,0,0)",
}
};
我在 javascript 文件中尝试了以下代码,但没有得到正确的输出。另外,我不知道如何调试。
var arrowcolor = document.getElementById('styles').innerHTML
this.colours = {
'normal' : {
'txt' : "rgb(255,255,255)",
'arrow':"'+arrowcolor+'",
}
};
解决方案
使用 value 而不是 innerHTML
var arrowcolor = document.getElementById('styles').value
this.colours = {
'normal' : {
'txt' : "rgb(255,255,255)",
'arrow':arrowcolor,
}
};
推荐阅读
- python - 如何通过限制数据框中的行大小来查找列总和?
- java - 如何在java中计算当前日期和另一个日期之间的距离
- python - 如何在 Tkinter 框架中放置基于数据框的饼图?
- owl - SWRL:表示类的变量(获取父类或子类实例的规则)
- android - 停止在颤动的列表视图中播放多个音频文件
- javascript - 使用 xlsx/ sheetjs 添加动态列
- elasticsearch - 在 K8S 中运行时,如何在 Elasticsearch 密钥库中添加 oidc 客户端密钥?
- javascript - 检查浏览器是否支持显示:内容
- python - Python List iter 和下一期
- date - swiftUI - 日期比较