为什么style.display没办法工作?
问题说明
为什么这行不通?应该检查display
css样式的元素.
Why won't this work? It should check the element for display
css style.
if (byId("annonsera_price").style.display=='inline' || byId("annonsera_price").style.display=='block'){
alert ("Hello");
}
function byId(x){
return document.getElementById(x);
}
update2:
<input type="text" name="annonsera_price" id="annonsera_price">
我也没有用CSS设置它!
I haven't set it with css either!
正确答案
首先尝试仅警告style.display并查看其包含的内容:
First try alerting just the style.display and see what it contains:
var el = document.getElementById("annonsera_price");
alert(el.style.display);
style
仅引用样式属性中的内容(或通过样式属性上的JS设置).显示可能是通过该类设置的,因此el.style.display
将不会显示任何内容.
style
only references what is in the style attribute (or set through JS on the style property). It's possible that the display is set through the class, and therefore el.style.display
won't show anything.
[更新]:鉴于更新,没有警报发生的原因是style.display
将是",而不是内联"或阻止".除非您在style
属性中或通过设置.style.display
对其进行设置,否则它不会是内联"或阻止".
[Update]:Given the update, the reason no alert happens is because style.display
will be "", not "inline" or "block". It won't be "inline" or "block" until you set it to something, either in the style
attribute or by setting .style.display
.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhccijig
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
使用c++17更新时出现G++编译器警告
it1352 06-18 -
复制文件夹/文件而不修改属性?
it1352 07-15