Javascript中alert的方法

Javascript中alert的方法:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>b indextitle>
<link rel='stylesheet' type="text/css" href='b/css/bootstrap.css'>
<style type="text/css">
    .s1{
        width: 100px;
        height: 100px;
        background-color: pink;
    }
    .s2{
        width: 50px;
        height: 50px;
        background-color: green;
    }
style>
head>
<body style="margin:1px;">
    <div id="div001">div001div>
    <div id='div002'>div002div>
    <div id='div003'>div003div>
    <div>
        <button id="btn001">click me to alert script button>
        <button id="btn002">click me to alert script button>
    div>
    <script type="text/javascript" src="js/jquery-1.11.1.js">script>
    <script type="text/javascript" src="b/js/bootstrap.js">script>
    <script type="text/javascript" src="js/index042.js">script>
    <script type="text/javascript">
        function btn001Click(e) {
            alert('<\/script>');
            // 如果写成下面这样,这个页面会出错;Uncaught SyntaxError: Unexpected token ILLEGAL
            //alert('');//即便这样写,也是有错误的;除非增加一个空格< / ,或者像上面转义一下;
        }
    script>
body>
html>
$(function() {
    $('#btn001').click(btn001Click);
    $('#btn002').click(btn002Click);
});
function btn002Click(e) {
    // 在js文件中,可以随意alert;
    alert('2');
}

 

你可能感兴趣的:(javascript,java)