[英]onfocus and onblur not working for input color element when visibility: hidden; is set
Onchange正在運作。 但是,當可見性隱藏時,使用輸入顏色元素觸發onfocus和onblur事件觸發的方法是什么? 設置好了嗎?
我在互聯網上看到的例子。 我正在使用它。 但是當我在css中設置下一個時它不起作用。
#colorDialogID {
visibility: hidden;
}
最后,如果在不進行任何更改的情況下打開和關閉顏色對話框,也許會有更好的解決方案來注冊?
function getColor2() {
console.log("change");
}
document.getElementById("colorDialogID").onchange = getColor2;
function myFocusFunction() {
console.log("open");
}
function myBlurFunction() {
console.log("close");
}
document.getElementById("colorDialogID").onfocus = myFocusFunction;
document.getElementById("colorDialogID").onblur = myBlurFunction;
var statusName;
function createStatusF(){
document.getElementById("colorDialogID").focus();
document.getElementById("colorDialogID").value = "#FFCC00";
document.getElementById("colorDialogID").click();
}
document.getElementById("newStatuslabelID").onclick = createStatusF;
您必須有一些重復的ID。
我為您做了這個演示:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<select id="colorDialogID">
<option value="#df0000">Red
<option value="#7b93d3">Blue
<option value="#000000">Black
</select>
<hr>
<span>Your selection</span>
<p id="selectedColor"></p>
</body>
</html>
JAVASCRIPT
function getColor2() {
var x = document.getElementById("colorDialogID").value;
document.getElementById("selectedColor").innerHTML = "You selected: " + x;
console.log("Selected color is:" + x);
}
document.getElementById("colorDialogID").onchange = getColor2;
function myFocusFunction() {
console.log("open");
}
function myBlurFunction() {
console.log("close");
}
document.getElementById("colorDialogID").onfocus = myFocusFunction;
document.getElementById("colorDialogID").onblur = myBlurFunction;
您可以調用類似此document.getElementById("colorDialogID").onfocus = function() {myFocusFunction()};
函數document.getElementById("colorDialogID").onfocus = function() {myFocusFunction()};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.