• html javascript 转移字符 单引号 双引号 动态事件绑定


    转义字符串(Escape Sequence)也称字符实体(Character Entity)。在HTML中,定义转义字符串的原因有两个:第一个原因是像“<”和“>”这类符号已经用来表示HTML标签,因此就不能直 接当作文本中的符号来使用。为了在HTML文档中使用这些符号,就需要定义它的转义字符串。当解释程序遇到这类字符串时就把它解释为真实的字符。在输入转义字符串时,要严格遵守字母大小写的规则。第二个原因是,有些字符在ASCII字符集中没有定义,因此需要使用转义字符串来表示。

    HTML特殊转义字符列表

    最常用的字符实体
    Character Entities

    显示 说明 实体名称 实体编号

    半方大的空白 &ensp; &#8194;

    全方大的空白 &emsp; &#8195;

    不断行的空白格 &nbsp; &#160;
    < 小于 &lt; &#60;
    > 大于 &gt; &#62;
    & &符号 &amp; &#38;
    " 双引号 &quot; &#34;
    © 版权 &copy; &#169;
    ® 已注册商标 &reg; &#174;
    商标(美国) &#8482;
    × 乘号 &times; &#215;
    ÷ 除号 &divide; &#247;

    其他字符

    字符 十进制 转义字符 字符 十进制 转义字符 字符 十进制 转义字符
    ? &#161; &iexcl; Á &#193; &Aacute; á &#225; &aacute;
    &#162; &cent; Â &#194; &circ; â &#226 &acirc;
    &#163; &pound; Ã &#195; &Atilde; ã &#227; &atilde;
    ¤ &#164; &curren; Ä &#196; &Auml ä &#228; &auml;
    &#165; &yen; Å &#197; &ring; å &#229; &aring;
    | &#166; &brvbar; Æ &#198; &AElig; æ &#230; &aelig;
    § &#167; &sect; Ç &#199; &Ccedil; ç &#231; &ccedil;
    ¨ &#168; &uml; È &#200; &Egrave; è &#232; &egrave;
    © &#169; &copy; É &#201; &Eacute; é &#233; &eacute;
    a &#170; &ordf; Ê &#202; &Ecirc; ê &#234; &ecirc;
    ? &#171; &laquo; Ë &#203; &Euml; ë &#235; &euml;
    ? &#172; &not; Ì &#204; &Igrave; ì &#236; &igrave;
    \x7f &#173; &shy; Í &#205; &Iacute; í &#237; &iacute;
    ® &#174; &reg; Î &#206; &Icirc; î &#238; &icirc;
    ˉ &#175; &macr; Ï &#207; &Iuml; ï &#239; &iuml;
    ° &#176; &deg; Ð &#208; &ETH; ð &#240; &ieth;
    ± &#177; &plusmn; Ñ &#209; &Ntilde; ñ &#241; &ntilde;
    2 &#178; &sup2; Ò &#210; &Ograve; ò &#242; &ograve;
    3 &#179; &sup3; Ó &#211; &Oacute; ó &#243; &oacute;
    &#180; &acute; Ô &#212; &Ocirc; ô &#244; &ocirc;
    μ &#181; &micro; Õ &#213; &Otilde; õ &#245; &otilde;
    ? &#182; &para; Ö &#214; &Ouml; ö &#246; &ouml;
    · &#183; &middot; &times; &#215; &times; ÷ &#247; &divide;
    ? &#184; &cedil; Ø &#216; &Oslash; ø &#248; &oslash;
    1 &#185; &sup1; Ù &#217; &Ugrave; ù &#249; &ugrave;
    o &#186; &ordm; Ú &#218; &Uacute; ú &#250; &uacute;
    ? &#187; &raquo; Û &#219; &Ucirc; û &#251; &ucirc;
    ? &#188; &frac14; Ü &#220; &Uuml; ü &#252; &uuml;
    ? &#189; &frac12; Ý &#221; &Yacute; ý &#253; &yacute;
    ? &#190; &frac34; Þ &#222; &THORN; þ &#254; &thorn;
    ? &#191; &iquest; ß &#223; &szlig; ÿ &#255; &yuml;
    À &#192; &Agrave; à &#224; &agrave;  

    ——————————————————————————————————————

    javascript转义字符

    转义字符 含义
    \b 退格
    \t TAB,水平
    \v TAB,垂直
    \n 回车换行
    \r 换行
    \" 双引号
    \' 单印号
    \\ \
    \uhhhh 十六进制编码的Unicode字符

    ——————————————————————————————————————

    <html>

    <body>

    <input value="外双引号内双引号-错误" type="button" onclick="alert("OK");" /><br />

    <input value="外单引号内单引号-错误" type="button" onclick='alert('OK');' /><br />

    <input value="两个双引号-错误" type="button" onclick="alert(""OK"");" /><br />

    <input value="两个单引号-错误" type="button" onclick="alert(''OK'');" /><br />

    <input value="\+双引号-错误" type="button" onclick="alert(\"OK\");" /><br />

    <input value="\+单引号-错误" type="button" onclick="alert(\'OK\');" /><br />

    <input value="外双引号内单引号-OK" type="button" onclick="alert('OK');" /><br />

    <input value="外单引号内双引号-OK" type="button" onclick='alert("OK");' /><br />

    <input value="外部不使用引号-OK" type="button" onclick=alert('OK');alert("OK"); /><br />

    </body>

    </html>

    //事件绑定函数alert中的参数,如果是数字可以直接写,如果是字符串要加单引号,其他函数也是这样

    //项目中的对比:

    1、传递参数为字符串

    searchResultContent = searchResultContent + "<tr><td align='center'>" + i + "</td><td align='center'>" + graphic.attributes["NAME"] + "</td><td align='center'>摄区</td><td align='center'>类型</td><td align='center'>生产时间</td>" + "<td align='center'" + "onclick = generateDetails('" + graphic.attributes["NAME"] + "');" + ">详细信息</td></tr>";

    2、传递参数为数字

    searchResultContent = searchResultContent + "<A " +"onclick = lightenGraphic(" + index + "," + position + ");" +  "href=\"javascript:void(0)\";>" +graphic.attributes["zonename"] + "</A>" + "   ";

    3、

     //事件绑定函数中传递参数,如果参数是数字,不用单引号,如果是字符串,要用单引号;

    //并列绑定的事件之间不需要加入分号,否则后边的事件不能绑定                  

    searchResultContent = searchResultContent + "<A " +

    "onmouseout = unlightenGraphic(" + index + ") " +

    "onclick = lightenGraphic(" + index + "," + position + ");" +

    "href=\"javascript:void(0)\"; style=\"cursor:pointer\";>" +

    graphic.attributes["zonename"] +

    "</A>" + "   ";

  • 相关阅读:
    JVM——类加载
    Java IO输入输出
    核心标签库和el
    request对象
    安装tomcat
    安装mongodb
    MySQL在简单命令行操作
    安装MySQL
    Java几种常见的异常类型
    Java简单正则表达式写爬虫
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1979252.html
Copyright © 2020-2023  润新知