在本文中,我们将给您介绍关于如何在输入中获取div的背景颜色-JavaScript的详细内容,并且为您解答获取div下的所有input的相关问题,此外,我们还将为您提供关于Android:在活动时更改
在本文中,我们将给您介绍关于如何在输入中获取 div 的背景颜色 - JavaScript的详细内容,并且为您解答获取div下的所有input的相关问题,此外,我们还将为您提供关于Android:在活动时更改 Material TextInputLayout 的背景颜色、css – 当输入为“:focus”时,如何更改表格行(tr)的背景颜色?、DIV 重叠 CSS 让 DIV 层叠 两个 DIV 或多个 DIV 顺序重叠加、iOS 14 中 UIPickerView 的背景颜色的知识。
本文目录一览:- 如何在输入中获取 div 的背景颜色 - JavaScript(获取div下的所有input)
- Android:在活动时更改 Material TextInputLayout 的背景颜色
- css – 当输入为“:focus”时,如何更改表格行(tr)的背景颜色?
- DIV 重叠 CSS 让 DIV 层叠 两个 DIV 或多个 DIV 顺序重叠加
- iOS 14 中 UIPickerView 的背景颜色
如何在输入中获取 div 的背景颜色 - JavaScript(获取div下的所有input)
如何解决如何在输入中获取 div 的背景颜色 - JavaScript
我不知道为什么这段代码不起作用!为什么它显示警报空白?
<html lang="en">
<head>
<title>Document</title>
<style>
#dd{
height: 300px;
width: 300px;
background-color: mediumblue;
color: white;
}
</style>
</head>
<body>
<label>Color </label><input id="in1" type="text">
<hr>
<div id="dd">
</div>
<script>
var colorTextBox = document.getElementById("in1");
var div = document.getElementById("dd");
div.onclick = function(){
colorTextBox.value = div.style.backgroundColor;
alert(div.style.backgroundColor);
}
</script>
</body>
</html>
当 div 被点击时,div 的背景颜色应该写在输入框内并显示在警报中。
解决方法
有了这个,它将计算 rgb 颜色: `
var colorTextBox = document.getElementById("in1");
var div = document.getElementById("dd");
div.onclick = function(){
//colorTextBox.value = div.style.backgroundColor;
//alert(div.style.backgroundColor);
const element = document.querySelector(''#dd'');
const style = getComputedStyle(element)
var color= style.backgroundColor;
alert(color);
}
<html lang="en">
<head>
<title>Document</title>
<style>
#dd{
height: 300px;
width: 300px;
background-color: mediumblue;
color: white;
}
</style>
</head>
<body>
<label>Color </label><input id="in1" type="text">
<hr>
<div id="dd">
</div>
<script>
</script>
</body>
</html>
`
,Element.style.<style>
只能检索内联样式。
例如,如果您将 div 更改为 <div id="dd">
,则 div.style.backgroundColor
将返回 mediumblue
。
要获得在您的样式标签中定义的背景颜色,您应该使用 getComputedStyle(Element)
代替。 getComputedStyle(div).backgroundColor
确实有效,返回 rgb(0,205)
,这是 mediumblue 的 rgb 值。
Demo
Android:在活动时更改 Material TextInputLayout 的背景颜色
如何解决Android:在活动时更改 Material TextInputLayout 的背景颜色
当 Material TextInputLayout 处于活动状态时,我试图更改它的背景颜色。 当我单击 textinputedittext 时,它变得透明,我需要设置背景颜色。 我正在附上打印屏幕。
非常感谢
first view
active text input with transparent color -need to keep same blue background not transparent
text input background color is correct when typing text
<com.google.android.material.textfield.TextInputLayout android:id="@+id/etPasswordLayout"/tag/Box/" target="_blank">Box.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="24dp" android:layout_marginTop="24dp" android:layout_marginRight="24dp" android:hint="Enter your password" app:endIconTint="@null" app:endIconMode="password_toggle" android:textColorHint="@color/darkBlue" app:endIconDrawable="@drawable/ic_password_visibility" app:shapeAppearance="@style/Rounded"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/etPassword"/tag/nor/" target="_blank">normalText" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/round_corner_toggle" android:inputType="textPassword" android:minHeight="60dp" android:text="" android:textColor="@color/darkBlue" /> </com.google.android.material.textfield.TextInputLayout>
textchangedlistener 的实现:
val layoutPassword = findViewById<TextInputLayout>(R.id.layout_Password)
val inputPassword = findViewById<TextInputEditText>(R.id.input_Password)
inputPassword.addTextChangedListener(object: TextWatcher {
override fun beforeTextChanged(s: CharSequence?,start: Int,count: Int,after: Int) {
layoutPassword.setBackgroundColor(Color.parseColor("#D0DDFF"))
inputPassword.setBackgroundColor(Color.parseColor("#D0DDFF"))
}
override fun onTextChanged(s: CharSequence?,before: Int,count: Int) {
layoutPassword.setBackgroundColor(Color.parseColor("#D0DDFF"))
inputPassword.setBackgroundColor(Color.parseColor("#D0DDFF"))
}
override fun afterTextChanged(s: Editable?) {
}
})
解决方法
使用addTextChangedListener
field1 = (TextInputLayout)findViewById(R.id.field1);
field2 = (TextInputEditText)findViewById(R.id.field2);
field2.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s,int start,int count,int after) {
// before text change
field1.setBackgroundColor() // set your color before active
}
public void onTextChanged(CharSequence s,int before,int count) {
// after add text in TextInputEditText
field1.setBackgroundColor() // set your color after active
}
});
css – 当输入为“:focus”时,如何更改表格行(tr)的背景颜色?
< tr>< td> Text< / td>< td>< input type =“text”value =“”>< / td>< / tr>
我的CSS:
输入:focus tr {background-color:#fff;}
当我在输入字段中写入文本时,我想突出显示白色的行.我知道“tr”是在“输入”之前,但是这可能以任何方式做吗?
感谢一堆
解决方法
虽然如此,可以做到这一点:http://jsfiddle.net/minitech/udzcp/
DIV 重叠 CSS 让 DIV 层叠 两个 DIV 或多个 DIV 顺序重叠加
http://www.divcss5.com/shili/s587.shtml
iOS 14 中 UIPickerView 的背景颜色
如何解决iOS 14 中 UIPickerView 的背景颜色?
UIPicker 上的背景似乎在 iOS 14 中发生了变化。我试图让它看起来与 iOS 13 中的一样,但我无法做到。以下是我现有的代码:
func pickerView(_ pickerView: UIPickerView,viewForRow row: Int,forComponent component: Int,reusing view: UIView?) -> UIView {
let pickerLabel = UIButton()
let attributesForSelectedRow = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16,weight: .bold),NSAttributedString.Key.foregroundColor: UIColor.blue(),NSAttributedString.Key.backgroundColor: UIColor(rgb: 0xE5E5E5)]
let attrTitle = NSMutableAttributedString(string: text,attributes: attributesForSelectedRow)
pickerLabel.setAttributedTitle(attrTitle,for: .normal)
pickerLabel.backgroundColor = UIColor(rgb: 0xE5E5E5)
pickerLabel.contentHorizontalAlignment = .center
return pickerLabel
}
我尝试过的解决方案:
func pickerView(_ pickerView: UIPickerView,reusing view: UIView?) -> UIView {
let pickerLabel = UIButton.init(frame: CGRect(x: 0,y: 0,width: pickerView.frame.width,height: 36))
if #available(iOS 14.0,*)
{
pickerView.subviews[safe:1]?.backgroundColor = UIColor.clear
}
let attributesForSelectedRow = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16,NSAttributedString.Key.backgroundColor: UIColor(rgb: 0xE5E5E5)]
let attrTitle = NSMutableAttributedString(string: “M1”,for: .normal)
pickerLabel.backgroundColor = UIColor(rgb: 0xE5E5E5)
pickerLabel.contentHorizontalAlignment = .center
return pickerLabel
}
我的解决方案的背景颜色看起来不错,但它不像 iOS 13 中那样采用 pickerview 的宽度。如何使灰色背景的宽度与选择器视图的宽度相同?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
今天关于如何在输入中获取 div 的背景颜色 - JavaScript和获取div下的所有input的介绍到此结束,谢谢您的阅读,有关Android:在活动时更改 Material TextInputLayout 的背景颜色、css – 当输入为“:focus”时,如何更改表格行(tr)的背景颜色?、DIV 重叠 CSS 让 DIV 层叠 两个 DIV 或多个 DIV 顺序重叠加、iOS 14 中 UIPickerView 的背景颜色等更多相关知识的信息可以在本站进行查询。
本文标签: