为什么调用不了重命名函数
<?php //读取管理项目,并且展示 require_once 'lib/dir.func.php'; define('WEBROOT','webRoot'); error_reporting(E_ALL&~E_NOTICE); $path=$_REQUEST['path']?$_REQUEST['path']:WEBROOT; $act=$_REQUEST['act']?$_REQUEST['act']:''; $dirName=$_REQUEST['dirName']?$_REQUEST['dirName']:''; $fileName=$_REQUEST['fileName']?$_REQUEST['fileName']:''; $info=read_directory($path); // var_dump($info);exit(); if(!is_array($info)){ // exit('读取失败'); exit("<script>alert('没有内容'); location.href='index.php'; </script>"); } switch ($act) { case 'createDir': // echo $dirName;exit; $res=create_dir($path.DIRECTORY_SEPARATOR.$dirName); if($res===true){ $result['msg']=basename($dirName).'目录创建成功'; $result['icon']=1; }else{ $result['msg']=$res; $result['icon']=2; } exit(json_encode($result)); break; case 'renameDir': $newName=$path.DIRECTORY_SEPARATOR.$dirName; $res=rename_dir($fileName,$newName); if($res===true){ $result['msg']=$fileName.'重命名成功'; $result['icon']=1; }else{ $result['msg']=$res; $result['icon']=2; } exit(json_encode($result)); } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> <title>在线文件管理器</title> <!-- Bootstrap --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet"> <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询(media queries)功能 --> <!-- 警告:通过 file:// 协议(就是直接将 html 页面拖拽到浏览器中)访问页面时 Respond.js 不起作用 --> <!--[if lt IE 9]> <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script> <![endif]--> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <nav class="navbar navbar-default" role="navigation"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">切换导航</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button> <a class="navbar-brand" href="index.php"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> 首页</a> </div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li class="active"> <a href="javascript:void(0)" id="createDir" data-url="index.php?act=createDir&path=<?php echo $path;?>"><span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> 新建目录</a> </li> <li> <a href="#"><span class="glyphicon glyphicon-file" aria-hidden="true"></span> 新建文件</a> </li> <li class="active"> <a href="#"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> 上传文件</a> </li> <li> <a href="#"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> 系统信息</a> </li> </ul> <form class="navbar-form navbar-left" role="search"> <div class="form-group"> <input type="text" class="form-control" /> </div> <button type="submit" class="btn btn-default">搜索</button> </form> </div> </nav> <div class="carousel slide" id="carousel-328612"> <ol class="carousel-indicators"> <li data-slide-to="0" data-target="#carousel-328612"> </li> <li data-slide-to="1" data-target="#carousel-328612"> </li> <li data-slide-to="2" data-target="#carousel-328612" class="active"> </li> </ol> <div class="carousel-inner"> <div class="item"> <img alt="" src="image/6.png" /> <div class="carousel-caption"> <h4> 焦点图一 </h4> <p> 焦点图一的描述,焦点图一的描述,焦点图一的描述,焦点图一的描述,焦点图一的描述, </p> </div> </div> <div class="item"> <img alt="" src="image/4.png" /> <div class="carousel-caption"> <h4> 焦点图二 </h4> <p> 焦点图二的描述,焦点图二的描述,焦点图二的描述,焦点图二的描述,焦点图二的描述,焦点图二的描述, </p> </div> </div> <div class="item active"> <img alt="" src="image/5.png" /> <div class="carousel-caption"> <h4> 焦点图三 </h4> <p> 焦点图三的描述,焦点图三的描述,焦点图三的描述,焦点图三的描述,焦点图三的描述, </p> </div> </div> </div> <a class="left carousel-control" href="#carousel-328612" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a> <a class="right carousel-control" href="#carousel-328612" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a> </div> <div class="jumbotron nofollow"> <h1> 文件管理器 </h1> <p> 在线管理器主要是用于管理项目文件,实现在线编辑、修改、删除等操作。 </p> <p> <a class="btn btn-primary btn-large" href="#">查看更多 »</a> </p> </div> <table class="table table-bordered table-hover table-condensed"> <thead> <tr> <th> 类型 </th> <th> 名称 </th> <th> 读/写/执行 </th> <th> 访问时间 </th> <th> 操作 </th> </tr> </thead> <tbody> <?php //目录部分 if(is_array($info['dir'])){ foreach ($info['dir'] as $val) { ?> <tr class="success"> <td><span class="glyphicon glyphicon-folder-close"></span></td> <td><?php echo $val['showName'];?></td> <td> <span class="glyphicon <?php echo $val['readable']?'glyphicon-ok':'glyphicon-remove';?>"></span> <span class="glyphicon <?php echo $val['writable']?'glyphicon-ok':'glyphicon-remove';?>"></span> <span class="glyphicon <?php echo $val['executable']?'glyphicon-ok':'glyphicon-remove';?>"></span> </td> <td><?php echo $val['atime'];?></td> <td> <a href="index.php?path=<?php echo $val['fileName']; ?>" class="btn btn-primary btn-sm">打开</a> <a href="javascript:void(0)" id="renameDir" class="btn btn-primary btn-sm " data-url='index.php?act=renameDir&fileName=<?php echo $val['fileName'];?>&path=<?php echo $path;?>' data-showName='<?php echo $val['showName']; ?>'>重命名</a> <a href="#" class="btn btn-primary btn-sm">剪切</a> <a href="#" class="btn btn-primary btn-sm">复制</a> <a href="#" class="btn btn-danger btn-sm">删除</a> </td> </tr> <?php } } ?> <?php //文件部分 if(is_array($info['file'])){ foreach ($info['file'] as $val) { ?> <tr class="info"> <td><span class="glyphicon glyphicon-file"></span></td> <td><?php echo $val['showName'];?></td> <td> <span class="glyphicon <?php echo $val['readable']?'glyphicon-ok':'glyphicon-remove'?>"></span> <span class="glyphicon <?php echo $val['writable']?'glyphicon-ok':'glyphicon-remove'?>"></span> <span class="glyphicon <?php echo $val['executable']?'glyphicon-ok':'glyphicon-remove'?>"></span> </td> <td><?php echo $val['atime'];?></td> <td> <a href="#" class="btn btn-primary btn-sm">查看</a> <a href="#" class="btn btn-primary btn-sm">下载</a> <a href="#" class="btn btn-primary btn-sm">编辑</a> <a href="#" class="btn btn-primary btn-sm">剪切</a> <a href="#" class="btn btn-primary btn-sm">复制</a> <a href="#" class="btn btn-danger btn-sm">删除</a> </td> </tr> <?php } } ?> </tbody> </table> <br> <br> <br> <br> <br> <br> <div id="footer"> <div class="footerNav"> <a href="#">关于我们</a> | <a href="#">服务条款</a> | <a href="#">免责声明</a> | <a href="#">网站地图</a> | <a href="#">联系我们</a> </div> <div class="copyRight"> Copyright ©2010-2019 Mr zhou 版权所有 </div> </div> </div> </div> </div> <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) --> <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script> <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script> <script src="layer/layer.js"></script> <script src="js/dir.js"></script> <script src="js/file.js"></script> </body> </html>
/创建目录 $('#createDir').on('click',function(){ // alert('vvvv'); // 加载layer var url=$(this).attr('data-url');//href=' '方法会跳转到页面的顶部,而javascript:void(0)方法不会。 3. attr() 方法设置或返回被选元素的属性值,所以可以接收到自定义属性。 // alert(url); layer.prompt({ /*formType: 1, //输入框类型,支持0(文本)默认1(密码)2(多行文本) value: '', //初始时的值,默认空字符 maxlength: 140, //可输入文本的最大长度,默认500*/ formType:0, // value: 'php', title: '新建目录', area: ['800px', '350px'] //自定义文本域宽高 }, function(value, index){ // alert(value); //得到value // 得到用户填写的值之后,通过ajax发送请求,将目录创建成功 $.ajax({ url:url+'&dirName='+value, type:'GET', success:function(data){ var obj=JSON.parse(data); // alert(obj); layer.alert(obj.msg,{icon:obj.icon},function(index){ //do something location.reload(); layer.close(index); }); } }); layer.close(index); }); }); //重命名目录 $('#renameDir').on('click',function(){ var url=$(this).attr('data-url'); var showName=$(this).attr('data-showName'); layer.prompt({ title:'重命名目录', value:showName, formType:0 },function(value,index){ $.ajax({ type:'GET', url:url+'&dirName='+value, success:function(data){ var obj=JSON.parse(data); layer.alert(obj.msg,{icon:obj.icon},function(index){ location.reload(); layer.close(index); }); } }); }); });
1
收起
正在回答 回答被采纳积分+1
1回答
好帮手慕小尤
2019-07-20 10:34:40
同学你好,在测试代码,发现同学使用id属性进行重命名的操作。因id是唯一的,所以使用id会使用在唯一的操作上,像重命名、删除操作使用class即可。代码如下:
<a href="javascript:void(0)" id="renameDir" class="btn btn-primary btn-sm renameDir" data-url='index.php?act=renameDir&fileName=<?php echo $val['fileName'];?>&path=<?php echo $path;?>' data-showName='<?php echo $val['showName']; ?>'>重命名</a> <!-- js代码 --> $('.renameDir').on('click',function(){ });
祝学习愉快!
PHP常用技术与ThinkPHP5框架开发
- 参与学习 人
- 提交作业 225 份
- 解答问题 3372 个
掌握用PHP开发互联网网站的必备功能,掌握当下主流的Linux系统开发,并熟练使用热门框架ThinkPhp开发电商团购项目,是通向PHP工程师必经之路。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星