js层

Posted liyiyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js层相关的知识,希望对你有一定的参考价值。

browseCourse.js

$(document).ready(function ()
    $("#addCourse").click(function ()
        $("#popup").css("display","block")
        $("#overlay").css("display","block")
    )
    $("#closebtn").click(function ()
        $("#popup").css("display","none")
        $("#overlay").css("display","none")
    )
    $("#myForm").bind("submit",function (event)
        event.preventDefault()
        $.ajax(
            url:"/manger/addCourse",
            method:"post",
            data:$("#myForm").serialize(),
            success:function (res)
                alert(res)
                location.reload()
            ,
            error:function ()
                alert("出错了!")
            
        )
    )
    $("#find").click(function ()
        location.replace("/manger/browseCourse?condition="+$("#condition").val()+"&teaCondition="+$("#teaCondition").val())
    )
    $("#stufind").click(function ()
        location.replace("/student/browseCourse?condition="+$("#condition").val()+"&teaCondition="+$("#teaCondition").val())
    )










)

browseHomework.js

$(document).ready(function ()
    $("#addVideo").click(function ()
        $("#popup").css("display","block")
        $("#overlay").css("display","block")
    )
    $("#closebtn").click(function ()
        $("#popup").css("display","none")
        $("#overlay").css("display","none")
    )
    $("#myForm").bind("submit",function (event)
        event.preventDefault()
        let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) 
            data.append(f[i].name,f[i].value)
            console.log(typeof (f[i].value))
        
        data.append("workfile",$("#homework")[0].files[0])
        $.ajax(
            url:"/teacher/addHomework",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res)
                alert(res)
                location.reload()
            ,
            error:function ()
                alert("出错了!")
            
        )
    )
    $("#homeworkLab1").click(function ()
        location.replace("/student/browseHomework?kind="+$("input[type=radio]:checked").val())
    )
    $("#homeworkLab2").click(function ()
        location.replace("/teacher/browseHomework?kind="+$("input[type=radio]:checked").val())
    )





)

browseStudent.js

$(document).ready(function ()
    $("#find").click(function ()
        location.replace("/manger/browseStudent?condition="+$("#condition").val())
    )
)

browseTeacher.js

$(document).ready(function ()
    $("#find").click(function ()
        location.replace("/manger/browseTeacher?condition="+$("#condition").val())
    )
)

browseVideo.js

$(document).ready(function ()
    $("#addVideo").click(function ()
        $("#popup").css("display","block")
        $("#overlay").css("display","block")
    )
    $("#closebtn").click(function ()
        $("#popup").css("display","none")
        $("#overlay").css("display","none")
    )
    $("#myForm").bind("submit",function (event)
        event.preventDefault()
        let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) 
            data.append(f[i].name,f[i].value)
        
        data.append("videoImg",$("#cover")[0].files[0])
        data.append("videos",$("#videos")[0].files[0])
        $.ajax(
            url:"/teacher/addVideo",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res)
                alert(res)
                location.reload()
            ,
            error:function ()
                alert("出错了!")
            
        )
    )
    $("#find").click(function ()
        location.replace("/teacher/browseVideo?condition="+$("#condition").val())
    )
    $("#find1").click(function ()
        location.replace("/student/browseVideo?condition="+$("#condition").val())
    )













)

changeMangerPwd.js

$(document).ready(function () 
    $("#myForm").bind("submit", function (event) 
        event.preventDefault()
        if ($("#newpwd1").val() !== $("#newpwd2").val()) 
            alert("新密码和确认密码不一致")
            return;
        
        $.ajax(
            url: "/manger/changePwd",
            method: "post",
            data: $("#myForm").serialize(),
            success: function (res) 
                alert(res)
            ,
            error: function () 
                alert("出错了!")
            
        )
    )

)

changeStudentPwd.js

$(document).ready(function ()
    $("#myForm").bind("submit",function (event)
        event.preventDefault()
        if($("#newpwd1").val()!==$("#newpwd2").val())
            alert("新密码和确认密码不一致")
            return;
        
        $.ajax(
            url:"/student/changePwd",
            method:"post",
            data:$("#myForm").serialize(),
            success:function (res)
              alert(res)
            ,
            error:function ()
                alert("出错了!")
            
        )
    )







)

changeTeacherPwd.js

$(document).ready(function () 
    $("#myForm").bind("submit", function (event) 
        event.preventDefault()
        if ($("#newpwd1").val() !== $("#newpwd2").val()) 
            alert("新密码和确认密码不一致")
            return;
        
        $.ajax(
            url: "/teacher/changePwd",
            method: "post",
            data: $("#myForm").serialize(),
            success: function (res) 
                alert(res)
            ,
            error: function () 
                alert("出错了!")
            
        )
    )
)

homeworkDetail.js

$(document).ready(function ()
    $("#myForm1").bind("submit",function (event)
        event.preventDefault()
        let data=new FormData()
        data.append("answerImg",$("#answerImg1")[0].files[0])
        $.ajax(
            url:"/student/addAnswer",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res)
                alert(res)
                location.reload()
            ,
            error:function ()
                alert("出错了!")
            
        )
    )
    $("#myForm2").bind("submit",function (event)
        event.preventDefault()
        let data=new FormData()
        data.append("answerImg",$("#answerImg2")[0].files[0])
        $.ajax(
            url:"/student/updateAnswer",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res)
                alert(res)
                location.reload()
            ,
            error:function ()
                alert("出错了!")
            
        )
    )
)

login.js

$(document).ready(function () 
    let sub;
    $("#sub1").click(function ()
        sub="登录"
    )
    $("#sub2").click(function ()
        sub="注册"
    )
    $("#myForm").bind("submit", function (event) 
        if(sub!="注册" || $("#kind").val()=="manger") 
            event.preventDefault()
            let data = $("#myForm").serialize()
            data = data + "&sub=" + sub
            $.ajax(
                url: "/login",
                method: "post",
                data: data,
                success: function (res) 
                    alert(res)
                    if (res === "登录成功") 
                        if ($("#kind").val() === "student") 
                            location.replace("/student/function")
                         else if ($("#kind").val() === "teacher") 
                            location.replace("/teacher/function")
                         else 
                            location.replace("/manger/function")
                        
                    
                ,
                error: function () 
                    alert(\'出错了!\')
                ,
            )
        
    )

)

mangerFunction.js

$(document).ready(function ()
    $("#closebtn").click(function ()
        $("#mySidenav").css("width","0px")
    )
    $("#openbtn").click(function ()
        $("#mySidenav").css("width","250px")
    )
    $("#a1").click(function ()
        $("#content").attr("src","/manger/toChangePwd")
        )
    $("#a2").click(function ()
        $("#content").attr("src","/manger/browseStudent")
    )
    $("#a3").click(function ()
        $("#content").attr("src","/manger/browseTeacher")
    )
    $("#a4").click(function ()
        $("#content").attr("src","/manger/browseCourse")
    )
    $("#a5").click(function ()
        location.replace("/")
    )













)

studentFunction.js

$(document).ready(function ()
    $("#closebtn").click(function ()
        $("#mySidenav").css("width","0px")
    )
    $("#openbtn").click(function ()
        $("#mySidenav").css("width","250px")
    )
    $("#a1").click(function ()
        $("#content").attr("src","/student/toChangePwd")
    )
    $("#a2").click(function ()
        $("#content").attr("src","/student/detail")
    )
    $("#a3").click(function ()
        $("#content").attr("src","/student/browseCourse")
    )
    $("#a4").click(function ()
        $("#content").attr("src","/student/myCourse")
    )
    $("#a5").click(function ()
        location.replace("/")
    )












)

stuRegister.js

$(document).ready(function ()
    let flag;
    $("#getflag").click(function ()
        $.ajax(
            url: "/student/getFlag",
            type:"post",
            data: "phone":$("#phone").val(),
            success:function (res) 
                flag = res;
            ,
            error:function ()
                alert("出错了!")
            

        )
    )
    $("#myForm").bind("submit",function (event)
        event.preventDefault()
        if(flag!=$("#flag").val())
            alert("验证码错误")
            $("#flag").css("value","")
            return;
        
       let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) 
            data.append(f[i].name,f[i].value)
        
        data.append("photo",$("#stuphoto")[0].files[0])
        $.ajax(
            url: "/student/register",
            method: "post",
            data: data,
            cache:false,
            contentType:false,
            processData:false,
            success: function (res) 
                alert(res)
                if (res === "注册成功") 
                    location.replace("/")
                
            ,
            error: function () 
                alert(\'出错了!\')
            ,
        )

    )
    $("#stucollege").change(function () 
        $("stumajor").append()
        let college = $("#stucollege").val()
        if (college === "信息科学与技术学院") 
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
            $("#stumajor").append($("<option>").val("计算机科学与技术").text("计算机科学与技术"))
            $("#stumajor").append($("<option>").val("软件工程").text("软件工程"))
            $("#stumajor").append($("<option>").val("数字媒体技术").text("数字媒体技术"))
            $("#stumajor").append($("<option>").val("信息工程").text("信息工程"))
            $("#stumajor").append($("<option>").val("人工智能").text("人工智能"))
            $("#stumajor").append($("<option>").val("网络工程").text("网络工程"))
         else if (college === "土木工程学院")
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
            $("#stumajor").append($("<option>").val("土木工程").text("土木工程"))
            $("#stumajor").append($("<option>").val("测绘工程").text("测绘工程"))
            $("#stumajor").append($("<option>").val("勘察技术与工程").text("勘察技术与工程"))
            $("#stumajor").append($("<option>").val("城市地下空间工程").text("城市地下空间工程"))
            $("#stumajor").append($("<option>").val("铁道工程").text("铁道工程"))
             $("#stumajor").append($("<option>").val("智能建造").text("智能建造"))

        
        else if (college === "机械工程学院")
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
            $("#stumajor").append($("<option>").val("机械设计制造及其自动化").text("机械设计制造及其自动化"))
            $("#stumajor").append($("<option>").val("机械电子工程").text("机械电子工程"))
            $("#stumajor").append($("<option>").val("建筑环境与能源应用工程").text("建筑环境与能源应用工程"))
            $("#stumajor").append($("<option>").val("测控技术与仪器").text("测控技术与仪器"))
            $("#stumajor").append($("<option>").val("车辆工程").text("车辆工程"))
            $("#stumajor").append($("<option>").val("工业设计专业").text("工业设计专业"))
        
        else 
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
        
    )
)

teacherFunction.js

$(document).ready(function ()
    $("#closebtn").click(function ()
        $("#mySidenav").css("width","0px")
    )
    $("#openbtn").click(function ()
        $("#mySidenav").css("width","250px")
    )
    $("#a1").click(function ()
        $("#content").attr("src","/teacher/toChangePwd")
    )
    $("#a2").click(function ()
        $("#content").attr("src","/teacher/detail")
    )
    $("#a3").click(function ()
        $("#content").attr("src","/teacher/myCourse")
    )
    $("#a4").click(function ()
        location.replace("/")
    )













)

teaRegister.js

$(document).ready(function ()
    let flag;
    $("#getflag").click(function ()
        $.ajax(
            url: "/teacher/getFlag",
            type:"post",
            data: "phone":$("#phone").val(),
            success:function (res) 
                flag = res;
            ,
            error:function ()
                alert("出错了!")
            

        )
    )
    $("#myForm").bind("submit",function (event)
        event.preventDefault()
        if(flag!=$("#flag").val())
            alert("验证码错误")
            return;
        
        let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) 
            data.append(f[i].name,f[i].value)
        
        data.append("photo",$("#teaphoto")[0].files[0])
        $.ajax(
            url: "/teacher/register",
            method: "post",
            data: data,
            cache:false,
            contentType:false,
            processData:false,
            success: function (res) 
                alert(res)
                if (res === "注册成功") 
                    location.replace("/")
                
            ,
            error: function () 
                alert(\'出错了!\')
            ,
        )

    )
)

 

js中如何判断一个层是不是隐藏

判断的JS语句怎么写,我是想写一个方法,判断一个层是隐藏还是显示,隐藏就显示它,显示就隐藏它,求解

<script type="text/javascript">
//下面的函数判断该层是否被隐藏,是则返回true,否则返回false
//参数为层对象的id
function isHidden (elementid)
var ele = document.getElementById(elementid);
//不等于none则说明未隐藏
if(ele.style.display != "none")
return false;
else
return true;



//下面的函数判断该层是否被隐藏,是则返回true,否则返回false
//参数为层对象
function isHiddenByElement (element)
var ele = element;
//不等于none则说明未隐藏
if(ele.style.display != "none")
return false;
else
return true;



//改变层的状态,
function changeDisplay (elementid)
var ele = document.getElementById(elementid);
if (isHiddenByElement(ele)) //若隐藏则显示之
ele.style.display = "block";
else //否则隐藏它
ele.style.display = "none";


</script>

在html代码中只需要对某个事件="changeDisplay(elementid)"即可
参考技术A <script>
function runcode ( name)
var div = document.getElementById(name);
// if (div.style.visibility == "hidden")
// div.style.visibility = "visible";
// else
// div.style.visibility = "hidden";
//

if (div.style.display == "none")
div.style.display = "block";
else
div.style.display = "none";




</script>

<form name=gomail method ="post" >
<body>
<div id=htmlText>ddddddddddd<br>ddddd</div>
<br><br>
<input type=button value="点这里" onclick="runcode('htmlText');">

</body>
</form>本回答被提问者采纳
参考技术B if (div.style.display == "none")
div.style.display = "block";
else
div.style.display = "none";

一般这样就可以了。其实也要看你最先是怎么设置样式的,才好控制,比如可以设置style.height=0;同样做到隐藏的效果。
参考技术C 在jquery中如果想查找一个可见的元素用 :visible
例如$("tr:visible")
如果想找不显示的,可以用
$("tr:not(':visible')")就行了

如果通过display的属性判断的话用
$("finder").css("display")
参考技术D XXXX.style.display = "none";
XXXX是一个层的名称或ID

XXXX.style.display = "bolck";
XXXX是一个层的名称或ID

刚才写了一个 能用
<html>
<head>
<title>ssss</title>
</head>
<SCRIPT language="JavaScript">

function showsubmenu(sid)
var whichEl = document.getElementById("submenu" + sid);
if (whichEl.style.display == "none")
eval("submenu" + sid + ".style.display=\"\";");
else
eval("submenu" + sid + ".style.display=\"none\";");


</SCRIPT>
<body>
<table align=center>
<tr>
<td width="158" height="25" id="menuTitle1" onClick="showsubmenu(1)" >专业管理</td>
</tr>
<tr>
<td style="display:none" id='submenu1'>
<div class=sec_menu style="width:158">
<table cellpadding=0 cellspacing=0 align=center width=130>
<tr>
<td height="20">专业大类管理</td>
</tr>
<tr>
<td height="20">添加专业(单)</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>

以上是关于js层的主要内容,如果未能解决你的问题,请参考以下文章

cocos2d-js教程cocos2d-js 遮挡层(禁止触摸事件传递层)

arcgis 中如何用js控制图层服务的层级顺序

怎么用JS隐藏一个DIV层?

js点击弹出提示层2秒钟之后自动消失

小程序视图层(xx.xml)和逻辑层(xx.js)

Vue.JS 中的服务层?