onclick必须点击两次才能触发(onclick has to be clicked twice to fire)
除非点击两次,否则我的onclick函数将不会触发。 我对javascript很新,但到目前为止,我在var obj行中移动,并将==“none”更改为“none”?“empty”; 这两件事我都不明白,但看到其他人解决这个问题。 都没有工作。
function showDiv(id){
var obj = document.getElementById(id);
if( obj.style.display == "none") {
obj.style.display='block'
}
else{
obj.style.display='none'
}
}
Roughly 2-3 months.
My onclick function won't fire unless it is clicked twice. I am very new to javascript but so far i trie moving around the var obj line, and changing the =="none" to "none"?"empty"; which are both things I didn't understand but saw other people did to fix this problem. Neither worked.
function showDiv(id){
var obj = document.getElementById(id);
if( obj.style.display == "none") {
obj.style.display='block'
}
else{
obj.style.display='none'
}
}
Roughly 2-3 months.
原文:https://stackoverflow.com/questions/27723191
2020-01-14 08:29
满意答案
你的问题是,你直接使用元素的style属性。 假设,你没有设置obj.style.display = "none"; 在你的代码中明确地说,直到第一次点击,该值仍然是undefined的。 在第一次点击之后,它就会被设置,并且一切都按照你想要的那样工作。
为了解决它,使用getComputedStyle()来访问元素的样式。 这包括通过CSS设置的所有样式:
function showDiv(id){
var obj = document.getElementById(id),
compStyle = window.getComputedStyle( obj );
if( compStyle.display == "none") {
obj.style.display='block'
} else {
obj.style.display='none'
}
}
Your problem is, that you use the style property of the element directly. Assuming, that you did not set obj.style.display = "none"; in your code explicitly, the value remains undefined until the first click. After the first click it is set and everything works like you want it to.
To solve it use getComputedStyle() to access the element's style. This includes all styles set via CSS:
function showDiv(id){
var obj = document.getElementById(id),
compStyle = window.getComputedStyle( obj );
if( compStyle.display == "none") {
obj.style.display='block'
} else {
obj.style.display='none'
}
}
2014-12-31
相关问答
修复它的方法有很多种...... (1)这是我修复同一问题的方式...因为我也想要自定义复选框...... 您可以使用已选中和未选中复选框的图像而不是复选框,并在tr点击时切换src ... 你也为所有不能工作的td提供了相同的id checkbox ... function toggleRowSelection(row){
if(row.getElementsByTagName('img')[0].src == "checked.jpg")
row.getElementsBy...
您正在向现有单元格添加多个事件处理程序。 这就是为什么我更喜欢使用普通的.onclick属性的原因之一。 无论如何,要解决此问题,您可以只将事件应用于新单元格,或者在添加事件时向它们添加属性,然后在再次添加事件之前检查该属性。 You are adding multiple event handlers to existing cells. This is one reason why I prefer to use just the plain old .onclick property. An...
这是一个略短的版本。 HTML
JS function showHide(id, event) {
var node = document.getElementById(id),
curr_display = node.style.display;
node.style.display = curr_display === "block" ? "none" : "blo...
另一种解决方案是覆盖透明div并向该div添加click事件。 工作样本: http : //jsfiddle.net/w1ll3m/AxJHH/
css将div.overlay放在iframe上: .container{position:relative;float:left;}
.overlay{top...
似乎highcharts在通过它传递事件时遇到了一些麻烦,无论是通过设计还是因为与SVG的某些冲突。 这就是说MoxieGroup有几种方法可以帮助你。 这是您应该使用单击处理程序添加到图表背景的方法。 单击系列或系列附近将不会触发此处理程序。 chart.setClickEventHandler(new ChartClickEventHandler() {
@Override
public boolean onClick(ChartClickEvent chartClickEv...
当你点击按钮内的文本或图像时,你实际上调用了window.onclick的js函数,这将删除div类。 您可以为该按钮添加一个ID并添加一个事件侦听器 function dropdown() {
document.getElementById("myDropdown").classList.toggle("show", true);
}
window.addEventListener('click', function(e){
if (!document.getEle...
您可以通过确保Btn_AddNewSite是LinkButton来完成此操作。
然后,您可以使用处理Link中的LinkButton单击的javascript代码,方法是使用它的UniqueID。 e.Row.Cells[column].Attributes.Add("onclick", "__do...
你的问题是,你直接使用元素的style属性。 假设,你没有设置obj.style.display = "none"; 在你的代码中明确地说,直到第一次点击,该值仍然是undefined的。 在第一次点击之后,它就会被设置,并且一切都按照你想要的那样工作。 为了解决它,使用getComputedStyle()来访问元素的样式。 这包括通过CSS设置的所有样式: function showDiv(id){
var obj = document.getElementById(id),
c...
事件多次触发事件的原因是点击事件正在冒泡到文档。 尝试使用event.stopPropagation()来防止事件冒泡, $("*").click(function(e)
{
e.stopPropagation()
console.log('fire -> ' + this.id );
});
演示 The reason why event firing multiple times is the click event is getting bubbled up to the Docu...
当您单击glyphicon plus而不是在其外部时, Click事件将起作用。 问题是您已将onClick事件放在错误的位置,将其添加到button而不是span ,它将起作用 render() {
return t7`
javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV
12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar
这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定