前端错误集

来源:互联网 发布:python opencv图像识别 编辑:程序博客网 时间:2024/05/22 15:56

==================================================================================

1.

2016年8月4日10:47:16

错误提示: Uncaught TypeError: Cannot set property 'height' of undefined

出现情景: byClassname获取元素后直接.sytle.height 设置高度时报错

尝试解决方案: byClassname 获取的元素, 要使用 example[0] 的方式获取到节点后才能设置, 而byId 的元素则不用.


==================================================================================


2 .

2016年8月4日10:47:44

错误提示: 

Uncaught ReferenceError: topheight is not defined

出现情景:

<span style="white-space:pre"></span><span style="white-space:pre"></span>funciton AA(){<span style="white-space:pre"></span><span style="white-space:pre"></span>    var testA = 1;<span style="white-space:pre"></span><span style="white-space:pre"></span>    BB();<span style="white-space:pre"></span><span style="white-space:pre"></span>}<span style="white-space:pre"></span><span style="white-space:pre"></span>function BB(){ <span style="white-space:pre"></span><span style="white-space:pre"></span>    console.log(testA ); // 报错<span style="white-space:pre"></span><span style="white-space:pre"></span>}

尝试解决方案: 

方法AA内声明的变量,引用的方法BB中无法获取,但是若吧testA提出至AA方法以外,则可以获取.


==================================================================================


3 . 

2016年8月4日13:59:07

错误提示 : 

Uncaught TypeError: Cannot set property 'height' of undefined

出现情景 : 

准备通过byClassname  改变下一级节点样式时 ,element[0].style....

错误原因 : 

<ul class="test">

<li></li>

</ul>

类节点<ul>后面若有换行,换行会被记为 #text , 此时 element[0]  为换行符 #text , 

若类节点<ul>后面没有换行,格式如: <ul class="test"><li>  ,  此时 element[1]  为标签 <li>

尝试解决方案 : 

若使用childNodes  将受换行符影响  

使用children,  将不受换行符影响, 最后获取标签中文本时,用childNodes[0];

classTop[0].children[0] .  childNodes[0]


==================================================================================


4

2016年8月4日20:02:01

错误描述: 用循环添加事件时,结果不如预期

错误代码 : 

<pre name="code" class="javascript">var topList = classTop[0].children[0].children;for (var i = 1; i < topList.length; i++) {var mylist = topList[i];var category = topList[i].children[0];mylist.addEventListener("mouseenter", function(){category.style.display = "block";},false);mylist.addEventListener("mouseout",function(){category.style.display = "none";},false);<span style="white-space:pre"></span>}

错误原因 : 不明;

解决方案 :

将添加事件的代码写在方法中即可;

<strong></strong>for (var i = 1; i < topList.length; i++) {var mylist = topList[i];var category = topList[i].children[0];topAddLsner(mylist,category);}


==================================================================================


5.
2016年8月30日10:51:01
错误描述: js给input动态赋值后,浏览器点击审查元素,input的value值设置正常 , 但是,单击submit提交后,php后台未能接收到值.
更多细节: 
  1.业务流程:
①点击需要改变的对象A
②输入改变的数据
③点击确认,将数据设置到input 的 value 中 
④提交表单 (此时后台打印input数据为空)
  2. 其他情况:
①点击需要改变的对象A
②输入改变的数据
③点击确认,将数据设置到input 的 value 中 
点击任意其他A的兄弟对象B
⑤提交表单 (此时后台打印input数据正常)

代码片段:
html
<form action="/admin/printer/setPosition" method="post"><div id ="position"><ul><li class="right"><span id="right_1">123456<input type="hidden" name="right_1" id="" value="" /></span></li><li class="left_1"><span id="left_1_1">张先生<input type="hidden" name="left_1_1" id="" value="" /></span>

JavaScript
给span标签添加点击事件
for (var i = 0; i < myspan.length; i++) {myspan[i].addEventListener("click",function(){var spanText = this.innerHTML.trim();adjust.children[0].innerHTML = spanText;clickEle = this.getAttribute("id");},false);}
 
给确认按钮添加点击事件
confirm.addEventListener("click",function(){if(clickEle==0){return;}var postion = adjustValue.value;var adjustEle = $e("#"+clickEle)[0];adjustEle.children[0].value = postion;adjustEle.style.marginLeft = postion+"px";},false);



解决状态 : 等待大神解惑.




0 0