星光斑斓里放歌 2022-06-21 10:15 采纳率: 85%
浏览 33
已结题

js中如何从函数中实现页面转换?

js中如何从函数中实现页面转换?
在树形结构中,想要根据结点进行页面转化
在setting的callback中定义了onClick函数
然后如何根据点击进行页面跳转呢?

主要就是onclick函数要怎么写?


function onclick(event, treeId, treeNode) {
                alert('页面转换');
                console.log(treeNode.id);
                //根据treeNode.id 进行页面跳转,当值为1时 跳转到htmla.html页面中
                if(treeNode.id == 1){
                    
                }

            }
<SCRIPT type="text/javascript">
            <!--
            var setting = {
                view: {
                    addHoverDom: addHoverDom,
                    removeHoverDom: removeHoverDom,
                    selectedMulti: false
                },
                edit: {
                    enable: true,
                    editNameSelectAll: true,
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                callback: {
                    beforeDrag: beforeDrag,
                    beforeEditName: beforeEditName,
                    beforeRemove: beforeRemove,
                    beforeRename: beforeRename,
                    onRemove: onRemove,
                    onRename: onRename,
                    onClick: onclick
                }
            };

            var zNodes = [{
                    id: 1,
                    pId: 0,
                    name: "卫星/平台",
                    open: true
                },

            ];
            var log, className = "dark";

            //点击事件
            function onclick(event, treeId, treeNode) {
                alert('页面转换');
                console.log(treeNode.id);
                //根据treeNode.id 进行页面跳转,当值为1时 跳转到htmla.html页面中
                if(treeNode.id == 1){
                    
                }

            }
            //禁止拖拽
            function beforeDrag(treeId, treeNodes) {
                return false;
            }


            //用于捕获节点编辑按钮的 click 事件,并且根据返回值确定是否允许进入名称编辑状态
            function beforeEditName(treeId, treeNode) {
                className = (className === "dark" ? "" : "dark");
                showLog("[ " + getTime() + " beforeEditName ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.selectNode(treeNode);
                setTimeout(function() {
                    if (confirm("进入节点 -- " + treeNode.name + " 的编辑状态吗?")) {
                        setTimeout(function() {
                            zTree.editName(treeNode);
                        }, 0);
                    }
                }, 0);
                return false;
            }

            //用于捕获节点被删除之前的事件回调函数
            function beforeRemove(treeId, treeNode) {
                className = (className === "dark" ? "" : "dark");
                showLog("[ " + getTime() + " beforeRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.selectNode(treeNode);
                return confirm("确认删除 节点 -- " + treeNode.name + " 吗?");
            }

            //用于捕获删除节点之后的事件回调函数
            function onRemove(e, treeId, treeNode) {
                showLog("[ " + getTime() + " onRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
            }
            //用于捕获节点编辑名称结束(Input 失去焦点 或 按下 Enter 键)之后,更新节点名称数据之前的事件回调函数,并且根据返回值确定是否允许更改名称的操作
            function beforeRename(treeId, treeNode, newName, isCancel) {
                className = (className === "dark" ? "" : "dark");
                showLog((isCancel ? "<span style='color:red'>" : "") + "[ " + getTime() +
                    " beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>" : ""));
                if (newName.length == 0) {
                    setTimeout(function() {
                        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                        zTree.cancelEditName();
                        alert("节点名称不能为空.");
                    }, 0);
                    return false;
                }
                return true;
            }
            //用于捕获节点编辑名称结束之后的事件回调函数。
            function onRename(e, treeId, treeNode, isCancel) {
                showLog((isCancel ? "<span style='color:red'>" : "") + "[ " + getTime() + " onRename ]&nbsp;&nbsp;&nbsp;&nbsp; " +
                    treeNode.name + (isCancel ? "</span>" : ""));
            }


            function showLog(str) {
                if (!log) log = $("#log");
                log.append("<li class='" + className + "'>" + str + "</li>");
                if (log.children("li").length > 8) {
                    log.get(0).removeChild(log.children("li")[0]);
                }
            }

            function getTime() {
                var now = new Date(),
                    h = now.getHours(),
                    m = now.getMinutes(),
                    s = now.getSeconds(),
                    ms = now.getMilliseconds();
                return (h + ":" + m + ":" + s + " " + ms);
            }

            var newCountxj = 1;
            var newCountpt = 1;

            function addHoverDom(treeId, treeNode) {
                var sObj = $("#" + treeNode.tId + "_span");
                if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
                if (treeNode.level == 0) {
                    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId +
                        "' title='添加相机' onfocus='this.blur();'></span>";
                    sObj.after(addStr);
                    var btn = $("#addBtn_" + treeNode.tId);
                    if (btn) btn.bind("click", function() {
                        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                        if (treeNode.level == 0) {
                            zTree.addNodes(treeNode, {
                                id: (100 + newCountxj),
                                pId: treeNode.id,
                                name: "相机" + (newCountxj++),

                            });
                        } else {
                            zTree.addNodes(treeNode, {
                                id: (200 + newCountpt),
                                pId: treeNode.id,
                                name: "激光平台" + (newCountpt++)
                            });
                        }
                        return false;
                    });
                } else {
                    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId +
                        "' title='添加光学系统' onfocus='this.blur();'></span>";
                    sObj.after(addStr);
                    var btn = $("#addBtn_" + treeNode.tId);
                    if (btn) btn.bind("click", function() {
                        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                        if (treeNode.level == 0) {
                            zTree.addNodes(treeNode, {
                                id: (100 + newCountxj),
                                pId: treeNode.id,
                                name: "相机" + (newCountxj++),

                            });
                        } else {
                            zTree.addNodes(treeNode, {
                                id: (200 + newCountpt),
                                pId: treeNode.id,
                                name: "激光平台" + (newCountpt++)
                            });
                        }
                        return false;
                    });
                }

            };

            function removeHoverDom(treeId, treeNode) {
                $("#addBtn_" + treeNode.tId).unbind().remove();
            };

            function selectAll() {
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.setting.edit.editNameSelectAll = $("#selectAll").attr("checked");
            }

            $(document).ready(function() {
                //创建tree的方法
                $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                $("#selectAll").bind("click", selectAll);
            });
            //-->
        </SCRIPT>

  • 写回答

1条回答 默认 最新

  • 浪客 2022-06-21 10:37
    关注

    document.location="http://www.baidu.com";

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月29日
  • 已采纳回答 6月21日
  • 创建了问题 6月21日

悬赏问题

  • ¥15 综合布线实例设计,就好看好看不恐怖可好滤镜好聚
  • ¥15 使用moviepy库视频合并时出错
  • ¥30 FLUENT液固传质UDF
  • ¥15 怎么看梯度直方图以,怎么判断梯度消失/爆炸,怎么解决
  • ¥15 aspnetdll文件访问拒绝
  • ¥15 wpf中在模版中寻找元素
  • ¥15 MFC平台生成指定圆
  • ¥15 jmeter出现403
  • ¥500 求华为P30PRO手机硬盘数据恢复
  • ¥15 关于#vscode#的问题:ESP32开发板对接MQTT实现小灯泡的开关