创建一个div对象 通过innerhtml赋值,在这里出现了这种怪问题,请问谁发生过类似问题?
给dim 赋值之后,再查看,获得的值和赋值不一样,难道是之前的html里面已经结构乱掉了,影响了这里么?
谁有明确的答案??100 分 ,绝对结贴
解决方案 »
- return false 的用法请教
- 请教一个js里的文字定位的方法
- ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●求能让这个正则 返回false的字符串!!!!!!!!!!!
- 求转为两位小数JS方法。
- 是高手者入内。。根据验证码图片求该数字
- 高手们,请帮我看看该怎么写才对
- 怎样用JAVASCRIPT脚本实现在WEB页面中不用刷新网页就能获得系统当前时间的程序?
- 想写一个函数,可以打印出对象的信息,结果却什么也没有,问错在哪里,应如何实现?
- 请教:表格中输入框失去焦点,使表格的底色改变???
- 急急急急急!正确答案双倍给分!谢谢!
- createElement 创建的对象如何快速设置样式?
- 图片显示问题!Discuz!NT 2.5.0
可以多贴点代码
你的代码这么少,只能说the_desc在哪个地方,值已经改变了!
2 上面那个tip 是赋值前 the_desc的值
3 下面那个是div innerhtml 赋值后,div.innerhtml的值显然两个不一样,不一样在哪儿,
the_desc的值
<a href='http://news.163.com/special/000113C4/weekinpicture.html'>111111111111</a> div.innerhtml的值
111111111111</a>
看出问题来了吧,这个是非常奇怪和少见的问题。坐等高人
GRulerControl.prototype.CreatePicture_MouseoverInfo = function(er) {
var the_div = document.createElement("div");
//div.innerHTML = er.MapSharp.Desc;
//var desc_dom = $(er.MapSharp.Desc);
//$(div).append(er.MapSharp.Desc);
var the_desc = this.CheckHTML(er.MapSharp.Desc);
if (the_desc.split(':')[0] == "src") {
var src = the_desc.substring(the_desc.indexOf("src") + 4);
var the_iframe = document.createElement("iframe");
the_iframe.src = src;
the_div.appendChild(the_iframe);
}
else {
the_div.innerHTML = the_desc;
}
return the_div;
}
the_div.innerHTML = "<span> + the_desc + "</span>";
这个方法是不是当鼠标over 是就会触发,可能此时改变了src的值了?
尽量少用innerHTML,有时候没有转义也会导致赋值操作和取值操作的html值不一样的
如:innerHTML = "<script>var i =0;</script>";
innerHTML ="<option value='1'>test one</option>";
这2个执行后的内容都不是这样的,只有一半;前面部分标签不见了;
原因就是部分标签是关键字导致赋值无效
如果用创建dom的方法就不同了
如果要插入一个链接
这样: var link = createElement("a");
link.setAttribute("href","#");
var text = createTextNode("click link");
link.appendChild(text);
document.byod.appendChild(link);
这样就创建了一个a标签的链接了
所以我觉着肯定是哪里出了问题,而且这个问题应该是人为的,我就想找到这个错误在哪儿。页面地址
http://119.167.225.131:1234/test.html________________________________________________________________
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body> <script> var the_div = document.createElement("div");
the_div.innerHTML = "<a href='http://news.163.com/special/000113C4/weekinpicture.html'>111111111111</a>";
alert(the_div.innerHTML);
the_div.innerHTML = "<div style='width:300px;height:300px;border:1px solid red;'>111111111111111111</div>";
alert(the_div.innerHTML);
the_div.innerHTML = "<a href='http://www.163.com'>111111111111111111</a>";
alert(the_div.innerHTML);
</script>
</body>
</html>
第二行var the_div = document.createElement("div");
我一直怀疑是原先里面的代码乱套了所以造成这样。但是我又搞不出到底哪儿乱套了,真闹人。
http://119.167.225.131:1234/test3.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div id="div1"></div>
<script>
var the_div = document.getElementById("div1");
the_div.innerHTML = "<a href=\"http://news.163.com/special/000113c4/weekinpicture.html\" >111111111111</a>";
alert(the_div.innerHTML);
</script>
</body>
</html>alert 出来是结果是错误的,寻求高手解释
<body>
<div id="div1"></div>
<script type="text/javascript">
var the_div = document.getElementById("div1");
the_div.innerHTML = "<a href=\"http://news.163.com/special/000113c4/weekinpicture.html\" >111111111111</a>";
alert(the_div.innerHTML); the_div.innerHTML = "<a href='http://news.163.com/special/000113c4/weekinpicture.html' >111111111111</a>";
alert(the_div.innerHTML); the_div.innerHTML = "<a href=http://news.163.com/special/000113c4/weekinpicture.html >111111111111</a>";
alert(the_div.innerHTML); the_div.innerHTML = "<a >2</a>";
alert(the_div.innerHTML); the_div.innerHTML = "<a onclick='alert(1);'>2</a>";
alert(the_div.innerHTML); </script>
</body>
</html>
用UE看了下,变成?号了
代码就成:the_div.innerHTML = "<a?href=\"http://news.163.com/special/000113c4/weekinpicture.html\" >111111111111</a>";
alert(the_div.innerHTML);
弹出来就是111111111111</a>了...
这一大长串都当作一个tag来处理,所以出现这种情况。
解决办法是在页面里写了一个attrValue.Replace(' ', ' '); 160空格转换成32空格
问题解决了,谢谢细心的Free_Wind22和zx119koko,看来有句话是正确的,出错的总是人,不是电脑 :<