JavaScript调试问题
2016-01-12 16:44
555 查看
JavaScript调试问题
获取element.style.width为空
请参考Width of a DIV is nothing according to Javascript, why?new problem. document.getElementById().width returning unassigned. why
如:
<style> div#foot_wrapper{ width:650px; height:20px; position:absolute; bottom:10px; background-color:#000000; } </style> <script> function align(div){ alert(div.style.width); // ---------------- box pops up blank? div.style.left = (window.innerWidth/2) - (div.style.width/2); } </script>
alert(div.style.width)弹出为空
主要原因为:
The style property only reflects the styles that were set inline on an element (using the style attribute on the element).
可以使用
div.offsetWidth来代替
return vs no return
参考:Javascript onclick return functionality如下:
<input type="checkbox" onclick="doAlert()" />
与
<input type="checkbox" onclick="return doAlert();" />
与
<a href='#' onclick='someFunc(3.1415926); return false;'>Click here !</a>类似
The return value of an event handler determines whether or not the default browser behaviour should take place as well.
event handler的返回值用来确定浏览器的默认行为是否发生
相关文章推荐
- JavaScript之Date
- JSF之经常使用注解
- input怎么限制只能输入数字?
- 框架操作DOM和原生js操作DOM比较
- 纯js实现点击一个事件后,触发另外一个事件的方法
- javascript array
- 返回按钮<a href="javascript:window.history.back(-1)"></a>
- javascript DOM元素操作汇总
- jackson的使用方法(二)
- JavaScript常用数组算法总结
- JavaScript-跨域实现方法总结
- JavaScript学习总结(6)——js弹出框、对话框、提示框、弹窗总结
- JavaScript学习总结(6)——js弹出框、对话框、提示框、弹窗总结
- JavaScript学习总结(6)——js弹出框、对话框、提示框、弹窗总结
- 与其他Javascript类库冲突解决方案
- 妙味课堂20160112js实例仿新浪菜单
- js判断一个地图标注点是否在多边形区域里
- Javascript 创建对象方法的总结
- Javascript 创建对象方法的总结
- js控制表单提交,新窗口打开