请问关于previousSibling和nextSibling的问题

ControlCoder8 2006-09-06 05:27:05
<span>1111</span>
<input type="text" onfocus="alert(this.previousSibling.innerHTML)" />
<span>1111</span>

我这样的代码

为什么每次都是弹出undefined啊

不管是previousSibling还是nextSibling都是这样的
...全文
179 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueDestiny 2006-09-06
  • 打赏
  • 举报
回复
糊涂了...刚才打着电话。我还以为贴错地方了呢
:D
BlueDestiny 2006-09-06
  • 打赏
  • 举报
回复
obj.cssText
----------------
obj.style.cssText
BlueDestiny 2006-09-06
  • 打赏
  • 举报
回复
sorry. 贴错了。
BlueDestiny 2006-09-06
  • 打赏
  • 举报
回复
<input type="text" onfocus="SetDefaultStyle(this,'333333','f0f8ff')" onblur="SetDefaultStyle(this,'cccccc','eeeeee')" />
<script type="text/javascript">
//<![CDATA[

function SetDefaultStyle(obj,borderColor,bgColor)
{
obj.style.cssText= "background-color:" +borderColor;
}
//]]>
</script>
hbhbhbhbhb1021 2006-09-06
  • 打赏
  • 举报
回复
先定义不同的样式,修改ClassName
或者一个一个设置
.style.width=""
... ...
ControlCoder8 2006-09-06
  • 打赏
  • 举报
回复
ControlCoder8 2006-09-06
  • 打赏
  • 举报
回复
我监视到上面的函数是执行了的
执行后的csstext也是正确的

可是input的外观就是没发生改变
ControlCoder8 2006-09-06
  • 打赏
  • 举报
回复
再请问一下

我通过这样来改变input的样式为什么不生效啊
<input type="text" onfocus="ClearMessage(this);SetDefaultStyle(this,'333333','f0f8ff')" onblur="ValidateData(9,this,'',1,'ff0000','');SetDefaultStyle(this,'cccccc','eeeeee')" /><div style="display:inline"></div>

function SetDefaultStyle(obj,borderColor,bgColor)
{
obj.cssText= "\"display:inline;width:175px;BORDER-RIGHT: #"+borderColor+" 1px solid; BORDER-TOP: #"+borderColor+" 1px solid; FONT-SIZE: 12px; BORDER-LEFT: #"+borderColor+" 1px solid; BORDER-BOTTOM: #"+borderColor+" 1px solid; FONT-FAMILY: verdana; BACKGROUND-COLOR: #" + bgColor+"\"";
alert(obj.cssText);
}
BlueDestiny 2006-09-06
  • 打赏
  • 举报
回复
<body id="www.never-online.net">
<span>1111</span>
<input type="text" onfocus="alert(this.previousSibling.innerHTML)" />
<span>1111</span>
<script type="text/javascript">
//<![CDATA[
var notspace = /\S/;

function cleanWhitespace(node) {
for (var x=0; x<node.childNodes.length; x++) {
var child = node.childNodes[x];
if ((child.nodeType == 3) && (!notspace.test(child.nodeValue))) {
node.removeChild(node.childNodes[x]); x--;
}; if(child.nodeType == 1) { cleanWhitespace(child); }
}
}
cleanWhitespace(document.body)
//]]>
</script>
</body>
ControlCoder8 2006-09-06
  • 打赏
  • 举报
回复
那如果我要获得下一个span节点怎么做呢
BlueDestiny 2006-09-06
  • 打赏
  • 举报
回复
因为空白节点的原因。
BlueDestiny 2006-09-06
  • 打赏
  • 举报
回复
<span>1111</span><input type="text" onfocus="alert(this.previousSibling.innerHTML)" /><span>1111</span>


这样就没事了
ControlCoder8 2006-09-06
  • 打赏
  • 举报
回复

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧