html : :
复制代码代码如下:
<! doctype html>
<html>
<head>
<title> عنوان الصفحة </title>
<type type = "text/css">
*{Font-Family: Consolas ؛ Font-Font: Mitalic}
.responsebox {العرض: 900px ؛ الهامش: 10px Auto ؛ Padding: 10px ؛ الحدود: 2px Solid #366 ؛ Border-Radius: 10px 0 10px 0 ؛ محاذاة النص: المركز}
.ResponseBox Inport ، زر .responsebox {font-size: 30px ؛ الهامش: 5px ؛ padding: 5px ؛}
.spansuper {alsal-align: super ؛ font-size: 14px}
.spanbottom {alsal-align: text-bottom ؛ font-size: 12px ؛ margin-left: -110px}
#showbox {width: 900px ؛ الارتفاع: 430px ؛ الحدود: 5px الصلبة #663 ؛ الحدود: 0 20px 0 20px ؛ الهامش: 10px auto ؛ padding: 8px ؛ font-size: 20px}
</style>
</head>
<body>
<viv>
<h1> javaScript base64 encode & decode <span> [email protected] </span> <span> 2014-12-27 17:44 </span> </h1>
<type type = "text" id = "input">
<type type = "checkbox" id = "checkbox" checked = "checked"> base64 </prope>
<button id = "btn"> تحويله! </button>
</div>
<div id = "showbox"> </viv>
</body>
<script type = "text/javaScript">
/*JavaScript : :
ام
*: : _string.replace (/(^/s*) | (/s*$)/g ، "") ؛
*
*covertbase64orstring 自执行函数
*inputid 输入框 id
*checkboxid 选择框 id
*btnid 按钮 id
*Showid html 显示容器 id , 这里是一个 div#showbox
*/
(وظيفة CovertBase64orString (InputId ، checkboxid ، btnid ، showid) {
var checkbox = document.getElementById (checkboxid) ؛ // HTML DOM حدد مربع الاختيار
var chkvalue = checkbox.getAttribute ("checked") ؛ // HTML DOM حدد checkedValue
var btn = document.getElementById (btnid) ؛ // HTML DOM حدد معرف الزر
var isbase64 ؛ // BASE64TOSTRING أو StringTobase64 BOOL
var returnval = null ؛ // تحويل السلسلة
chkvalue == "فحص"؟ ISBase64 = true: isBase64 = false ؛ // 判断 تحقق من 按钮初始化状态 赋值 isBase64
checkbox.adDeventListener ("Click" ، Function (E) {// checkbox 点击事件注册
var _ckvak = checkbox.getAttribute ("checked") ؛ // 点击事件发生时 , 改变 تحقق 状态 , 赋值 isBase64
if (_ckvak == "فحص") {
checkbox.setAttribute ("checked" ، null) ؛
isBase64 = false ؛
} آخر {
checkbox.setAttribute ("checked" ، "checked") ؛
ISBase64 = صحيح ؛
}
}، حقيقي)؛
btn.addeventListener ("انقر" ، الدالة (e) {// الزر 点击事件注册
var _show = document.getElementById (showid) ؛ // HTML DOM SELECT SHOWBOX ID
var _inputValue = document.getElementById (inputId) .value ؛ // 文本框取值
//_inputvalue=_inputvalue.replace(/(^/S*)|(/s*$)/g ، "") ؛ // 正则表达式去除首位空格 , 似乎 btoa , abob 已经做了这些工作
var _showlength = _show.childnodes.length ؛ // 遍历 showbox , 清除 showbox 内容
بينما (_showlength> 0) {
_show.removechild (_show.childnodes [_showlength - 1]) ؛
_showlength-- ؛
}
if (isBase64) {// string to base64 , 支持中文编码 , unescape , EncodeUricomponn
returnval = window.btoa (unescape (EncodeUricomponent (_inputValue))) ؛
} آخر {// base64 إلى سلسلة
returnval = decodeuricomponent (excart (window.atob (_inputValue)))) ؛
}
_show.appendChild (document.createTextNode (returnval)) ؛ // إضافة سياق إلى showbox
}، حقيقي)؛
}) ("input" ، "مربع الاختيار" ، "btn" ، "showbox") ؛
// covertbase64orstring ("input" ، "checkbox" ، "btn" ، "showbox") ؛
</script>
</html>
: :
推荐一个 javaScript ide 比 aptana 还好用。komodo ide (免费版 : komodo edit , 基本功能一样 支持语法高亮 , , 智能感知 还支持 还支持 perl , python , ruby , nodejs 语法等。