什么是<%=%>标签在HTML?

时间:2014-09-08 16:08:38

标签: html

我在html页面中有以下代码:

<div class="bd">
   <h1><%= user.fullname %></h1>
</div>

什么是&lt;%=%&gt;标签?这是标准的HTML吗?我以前从未见过它。 (user.fullname是一个javascript变量)

以下是该页面的完整代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/layout.css">
    <link rel="stylesheet" href="css/styles.css">
    <script language="javascript">

        // We use this code for handling unexpected errors.
        // Using alert, we are sure that the user get notified in a Mobile device.
        // We add this code at the begining of the index.html and we use only native javascript functions.
        window.onerror = function(msg, url, lineNumber) {
            if (typeof(msg) === "string") {
                var error = msg + "\n\nFile: " + url + "\nLine: " + lineNumber;
                // Ommit cordova and 3rd party libs errors.
                if (url.indexOf("cordova.js") == -1 && url.indexOf("externallib") == -1) {
                    window.alert(error);
                }
            } else {
                var error = msg;
            }

            // This may help debugging if we use logging apps in iOs or Android.
            if(typeof(console) !== "undefined" && typeof(console.log) === "function") {
                console.log(error);
            }

            // Let default error handler run.
            return false;
        };

    </script>
    <script src="cordova.js"></script>
    <script src="childbrowser.js"></script>
    <script src="webintent.js"></script>
    <script src="PushNotification.js"></script>
    <script src="externallib/jquery.min.js"></script>
    <script src="externallib/jquery.touchSwipe.min.js"></script>
    <script src="externallib/md5.js"></script>
    <script src="externallib/matchMedia.js"></script>
    <script src="externallib/matchMedia.addListener.js"></script>
    <script src="externallib/underscore.js"></script>
    <script src="externallib/backbone.js"></script>
    <script src="externallib/backbone-localstorage.js"></script>
    <script src="lib/mm.js"></script>
    <script src="lib/mm.panels.js"></script>
    <script src="lib/mm.util.js"></script>
    <script src="lib/mm.lang.js"></script>
    <script src="lib/mm.db.js"></script>
    <script src="lib/mm.tpl.js"></script>
    <script src="lib/mm.cache.js"></script>
    <script src="lib/mm.settings.js"></script>
    <script src="lib/mm.widgets.js"></script>
    <script src="lib/mm.sync.js"></script>
    <script src="lib/mm.emulator.js"></script>
    <script src="lib/mm.rdebugger.js"></script>
    <script src="lib/mm.fs.js"></script>
    <script data-main="lib/app.js" src="externallib/require.js"></script>
    <script language="javascript">
        // We should wait to phonegap, if not, we get errors like:
        // http://rickluna.com/wp/2012/04/solving-the-connection-to-the-server-was-unsuccessful-error-in-androidphonegap/
        $(document).bind('deviceready', function() {
            MM.log('Deviceready fired');
            MM.deviceReady = true;
            // Store the device locale for further uses.
            navigator.globalization.getLocaleName(
                function (locale) {
                    MM.lang.locale = locale.value;
                    MM.log("Device locale loaded: " + locale.value);
                },
                function () {}
            );
            // Disable the back button, exists the app.
            document.addEventListener("backbutton", function() {
                MM.panels.goBack();
            }, false);

            // Call deviceIsReady function in plugins.
            // Plugins may not be able to listen for the deviceready event because it's possible that it was fire
            // when plugins whasn't loaded, we use a timeout of 5 seconds.
            setTimeout(function() {
                for (var el in MM.plugins) {
                    var plugin = MM.plugins[el];

                    if (typeof(plugin.deviceIsReady) == 'function') {
                        plugin.deviceIsReady();
                    }
                }
            }, 5000);
            MM.fs.init();
        });

        // This function is for handling when the app is opened using a custom URL SCHEME.
        function handleOpenURL(url) {
            MM._appLaunchedByURL(url);
        }
    </script>

    <style id="mobilecssurl"></style>
</head>
<body>

<div id="add-site" style="display: none">

</div>

<div id="manage-accounts" style="display: none">

</div>

<div id="main-wrapper" style="display: none; background-color: white">

    <div class="header-wrapper">
        <header class="header-main">
            <nav class="nav-main">
                <ul class="nav">
                    <li class="nav-item home menu-home">
                        <a href="#" class="ir"  id="mainmenu">
                            Home
                        </a>
                    </li>
                </ul>
                <span id="page-title"></span>
            </nav>
        </header>
    </div>

    <div id="panel-left" class="panel user-menu"></div>

    <div id="panel-center" class="panel"></div>

    <div id="panel-right" class="panel"></div>
</div>

<div id="app-dialog">
    <div>
        <div class="modalHeader">
        </div>
        <div class="modalContent">
        </div>
        <div class="modalFooter">
        </div>
        <div class="modalClear"></div>
    </div>
</div>

<script type="text/template" id="menu_template">
<header>
    <div class="media">
        <div class="refresh app-ico">
            <a href="#refresh">
                <img width="16" height="16" src="img/reload.png" border="0">
            </a>
        </div>
        <div class="img">
            <img src="<%= MM.util.getMoodleFilePath(user.profileimageurl) %>" border="0">
        </div>
        <div class="bd">
            <h1><%= user.fullname %></h1>
        </div>
    </div>
</header>

</body>
</html>

5 个答案:

答案 0 :(得分:4)

  

html中的<%= %>标记是什么?

没有。有几个模板引擎使用<%%>来分隔模板或代码块,但是:Active Server Pages(ASP),JavaServer Pages(JSP),可能还有其他。那些通常进行服务器端处理,并将<% ... %>中的文本替换为应该去的地方。

例如,在你的例子中

<h1><%= user.fullname %></h1>

如果在请求资源时user对象的fullname属性为"Joe Bloggs",则引擎会在发送文本之前将其交换为该令牌,那么浏览器实际看到的是

<h1>Joe Bloggs</h1>

在您的情况下,正如您所指出的那样,处理正在客户端进行。您的<% ... %>代币位于<script type="text/template">...</script>个区块内,因此<并非特殊。 (在DCoder向我指出之前,我在这里有一个复杂的解释,为什么它有效...但是,呃,DCoder指出它们在script块中,所以......)

DCoder also identified这些是由backbone.js处理的模板,它重用了underscore.js的模板。

答案 1 :(得分:2)

  

html中的<%= %>标记是什么?

T.J. Crowder said类似,它不是HTML标记,它来自客户端模板引擎,恰好使用这些表达式来指示动态插值内容的开头/结尾。

  

如何找出使用的模板引擎? (它不是ASP或JSP)

根据您的网页加载backbone.js的事实,模板引擎最有可能backbone's template engine,实际上是从underscore.js借来的。

答案 2 :(得分:0)

这是您正在看到的ASP.NET或JavaScript标记。

答案 3 :(得分:0)

这通常是服务器端编程的一种形式。它可以是JSP(在Java中),ASP甚至是PHP(启用asp tags)。它将使用服务器端变量的值替换<%= %>的内容(在服务器响应时间)。

答案 4 :(得分:-1)

声明'&lt;%= user.fullname%&gt;'评估属性'user.fullname'并将其呈现为字符串。 'user'对象可以作为页面上的属性存在,也可以是静态类类型。