在获取树的Node值时,当我点击子菜单时,虽然它被放置在输入字段txt内,但是有错误....错误说
消息:'target.childNodes.0.nodeValue'为null或不是对象
行:9
Char:3
代码:0
任何帮助???谢谢..
HTML
<ul id="browser" class="filetree">
<li><span class="folder">Souvik_Workspace</span>
<ul>
<li><span class="file">Item 1.1</span></li>
</ul>
</li>
<li><span class="folder">Folder 2</span>
<ul>
<li><span class="folder">Subfolder 2.1</span>
<ul id="folder21">
<li><span class="file">File 2.1.2</span></li>
</ul>
</li>
</ul>
</li>
<li class="closed"><span class="folder">Folder 3 (closed at start)</span>
<ul>
<li><span class="file">File 3.1</span></li>
</ul>
</li>
<li><span class="file">File 4</span></li>
</ul>
jQuery
$("#browser >li").click(function(clk){
var $val = clk.target.childNodes[0].nodeValue
$("#workspace").attr('value',$val);
});
答案 0 :(得分:0)
只需删除$val
变量上的“$”!
jsfiddle和chrome开发人员工具是调试简单代码的好方法。 http://jsfiddle.net/bouillard/PUjHf/