ExtJS:如何切换 html 视图
ExtJS: how to toggle an html view
我有一个带按钮的 HTML 代码。单击按钮时,某些对象应该切换。这目前不起作用。
var contentString = '<a href="#" onclick="someFunction()">' + testVariable + '</a><br><button onclick="document.getElementById(\'demo\').toggle()">BUTTON TOGGLE</button><br><p id= "demo">' + hideVariableOnToggle + '</p>';
var infoWindow = new google.maps.InfoWindow({
content: '<div style="min-height:50px; color:black; width: 300px;">' + contentString + '</div>'
});
我收到以下错误
TypeError: document.getElementById(...).toggle is not a function
<!DOCTYPE HTML>
另外,如何通过 ID 访问元素?目前我的所有尝试都为空
Ext.get('demo') //null
document.getElementById('demo')//null
Ext.getCmp('demo')//null
您拥有的元素 P 是一个 Html 元素并且没有实现 toggle() 函数,除非您使用 JQuery。您可以尝试更改 显示 属性 以隐藏或显示对象
function toggle(obj){
obj.style.display = (obj.style.display == 'none' ? '' : 'none');
}
您可以在按钮中使用此功能:
<button onclick="toggle(document.getElementById('demo'));">BUTTON TOGGLE</button>
我有一个带按钮的 HTML 代码。单击按钮时,某些对象应该切换。这目前不起作用。
var contentString = '<a href="#" onclick="someFunction()">' + testVariable + '</a><br><button onclick="document.getElementById(\'demo\').toggle()">BUTTON TOGGLE</button><br><p id= "demo">' + hideVariableOnToggle + '</p>';
var infoWindow = new google.maps.InfoWindow({
content: '<div style="min-height:50px; color:black; width: 300px;">' + contentString + '</div>'
});
我收到以下错误
TypeError: document.getElementById(...).toggle is not a function
<!DOCTYPE HTML>
另外,如何通过 ID 访问元素?目前我的所有尝试都为空
Ext.get('demo') //null
document.getElementById('demo')//null
Ext.getCmp('demo')//null
您拥有的元素 P 是一个 Html 元素并且没有实现 toggle() 函数,除非您使用 JQuery。您可以尝试更改 显示 属性 以隐藏或显示对象
function toggle(obj){
obj.style.display = (obj.style.display == 'none' ? '' : 'none');
}
您可以在按钮中使用此功能:
<button onclick="toggle(document.getElementById('demo'));">BUTTON TOGGLE</button>