试试:NSString *js = @"var element = document.getElementById('header');  element. parentNode. removeChild(element);";
NSString *res = [webview stringByEvaluatingJavaScriptFromString:js];

解决方案 »

  1.   

    还是不行哦,还有没有其他的方法?
    把你web的源码发上来
      

  2.   

    还是不行哦,还有没有其他的方法?
    把你web的源码发上来
    <!DOCTYPE html>
    <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
    <!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
    <!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
    <!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
    <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"><!--<![endif]-->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>我的考勤情况</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/tms/assets//favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon" href="/tms/assets//apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/tms/assets//apple-touch-icon-retina.png">
    <link rel="stylesheet" href="/tms/assets/application-8b6ca475405ef1bc971055ff3be99861.css"/>
    <script src="/tms/assets/application-26c38fa7c3e6771360c437e258af7623.js" type="text/javascript" ></script><meta name="layout" content="main"/><link rel="stylesheet" href="/tms/assets/rollcall-statis/student-435c897fb7fd8239044f2a7cbca04e06.css"/>
    <script src="/tms/assets/rollcall-statis/student-5793c86d4507c66f53dfe5900c6a5d6f.js" type="text/javascript" ></script>
    <!--[if lt IE 9]>
    <script src="/tms/assets/bs-ie8-7d4aa1cf1f938c108191b198f71226b4.js" type="text/javascript" ></script>
    <![endif]-->
    </head>
    <body>
    <div id="header" class="navbar navbar-inverse navbar-static-top">
    <div class="container">
    <div class="navbar-header">
    <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
           </button>
           <a class="navbar-brand"><span id="logo" style="display:inline-block;width:30px"></span></a>
         </div>
    <div class="collapse navbar-collapse bs-navbar-collapse">
    <ul class="nav navbar-nav"><li><a href="/tms/">Home</a></li><li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Activity <b class="caret"></b></a><ul class="dropdown-menu"><li><a href="/tms/leaves/new">Create Leave</a></li><li><a href="/tms/cardReissueRequests/new">Reissue Student Card</a></li><li><a href="/tms/bookings/new">Classroom booking</a></li></ul></li><li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Query <b class="caret"></b></a><ul class="dropdown-menu"><li><a href="/tms/rollcall/personal">My Rollcall</a></li><li><a href="/tms/leaves">My Leaves</a></li><li><a href="/tms/schedule/student">My Schedule</a></li><li><a href="/tms/bookings">My Bookings</a></li><li><a href="/tms/placeUsage">menu.queryPlaceUsage</a></li><li><a href="/tms/addresses">AdminClass Address List</a></li></ul></li><li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Feedback <b class="caret"></b></a><ul class="dropdown-menu"><li><a href="/tms/issues/new">Create Issue</a></li><li><a href="/tms/issues">All Issues</a></li><li><a href="/tms/issues?personal">My Issues</a></li></ul></li></ul>
    <ul class="nav navbar-nav navbar-right">
    <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">陈杰豪 <b class="caret"></b></a>
    <ul class="dropdown-menu">
    <li><a href="/tms/profile">修改个人信息</a></li>
    <li class="divider"></li>
    <li><a href="/tms/logout">退出</a></li>
    </ul>
    </li>
    </ul>
    </div>
    </div>
    </div>
    <div class="container">

        <div id="rollcallStatis"></div>
        <script id="statis-template" type="text/x-dot-template">
    <h4>考勤</h4>
    <ul class='list-unstyled rollcall-items'>
    {{? it.rollcallItems.length}}
    {{~ it.rollcallItems :ri}}
    <li>
    <label class='label {{= ri.typeClass()}}'>{{= ri.typeText()}}</label>
    <span {{? ri.type < 0}}style="text-decoration:line-through;"{{?}}>
    {{=ri.weekText()}}&nbsp;
    {{=ri.arrangement.dayOfWeekText()}}&nbsp;
    {{=ri.arrangement.sectionsText()}}&nbsp;
    {{=ri.teacher}}&nbsp;
    {{=ri.arrangement.courseText()}}
    </span>
    </li>
    {{~}}
    {{?? true}}
    <li>暂无考勤数据</li>
    {{?}}
    </ul>
    <h4>请假</h4>
    <ul class='list-unstyled leave-items'>
    {{? it.leaveItems.length }}
    {{~ it.leaveItems :li}}
    <li>
    <label class='label {{= li.typeClass()}}'>{{= li.typeText()}}</label>
    <span>
    {{=li.weekText()}}&nbsp;
    {{=li.dayOfWeekText()}}&nbsp;
    {{=li.sectionsText()}}&nbsp;
    {{=li.courseText()}}&nbsp;
    </span>
    </li>
    {{~}}
    {{?? true}}
    <li>暂无请假数据</li>
    {{?}}
    </ul>
    <h4>课程</h4>
    <ul class='list-unstyled course-items'>
    {{? it.courses.length}}
    {{~ it.courses :ci}}
    <li>
    <label class='label {{=(ci.statis / ci.hours >= 1 / 9) ? "label-danger": "label-default"}}'>
    {{= ci.statis}}/{{= ci.hours}}
    </label>
    <span>{{= ci.course}}</span>
    </li>
    {{~}}
    {{?? true}}
    <li>暂无课程数据</li>
    {{?}}
    </ul>
    </script></div>
    <div id="footer">
    <div class="container">
       <span class="pull-right"><a href="http://www.bnuz.edu.cn" target="_blank">北京师范大学珠海分校</a></span>
       <span><a href="/tms/about">关于我们</a> </span>
    </div>
    </div>
    <script src="/tms/assets/logo-35ac5e4e90a099142f72c28dbf683d2e.js" type="text/javascript" ></script>
    <script >
    $(function(){
    $("#rollcallStatis").rollcallStatisStudent({
    rollcallItems: [{"week":11,"dayOfWeek":2,"courseClass":"管理信息系统","teacher":"赵丕显","totalSection":3,"type":2,"startSection":7},{"week":11,"dayOfWeek":3,"courseClass":"财务管理","teacher":"毕劲","totalSection":2,"type":2,"startSection":3}], 
    leaveItems:    [],
    courses:       [{"course":"管理信息系统","hours":51.0,"statis":1.5},{"course":"财务管理","hours":34.0,"statis":1.0}]
    });
    });
    </script>
    </body>
    </html>
    我就是想把id为header的层删掉
      

  3.   

    那基本上可以确定是stringByEvaluatingJavaScriptFromString这个方法执行时机的问题了,你应该把它放在webViewDidFinishLoad回调里执行