實現將表單中的數據提交到商務通后臺的效果,中文說明并且實現換行顯示。
代碼簡單容易理解,這里就不多解釋了。
要點:1、使用escape函數對中文進行編碼;2、使用br標簽進行換行。
效果如下圖:
前臺界面
提交到商務通后臺的結果
提交到商務通后臺的結果
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>表單提交到商務通后臺 中文說明加換行的實現方法</title>
<style type="text/css">
#yuyue {width:320px;margin:0 auto;}
</style>
</head>
<body>
<div id="yuyue">
<p>姓名: <input type="text" id="gname"></p>
<p>年齡: <input type="text" id="gage"></p>
<p>電話: <input type="text" id="gphone"></p>
<p>留言: <textarea id="gmsg" cols="30" rows="4"></textarea></p>
<p><input type="button" value="提交" onclick="submit_to_swt();"></p>
</div>
<script type="text/javascript">
function submit_to_swt(){
var name = document.getElementById("gname");
var age = document.getElementById("gage");
var phone = document.getElementById("gphone");
var msg = document.getElementById("gmsg");
if(name.value==""){
alert("請輸入您的姓名!");
name.focus();
return false;
}
if(age.value==""){
alert("請輸入您的年齡:!");
age.focus();
return false;
}
if(phone.value==""){
alert("請輸入您的電話!");
phone.focus();
return false;
}
if(msg.value==""){
alert("請輸入您的留言:!");
msg.focus();
return false;
}
if(typeof openZoosUrl != "undefined"){
openZoosUrl('chatwin','&e='+escape('姓名:'+name.value+'<br/>年齡:'+age.value+'<br/>電話:'+phone.value+'<br/>留言:'+msg.value));
}
}
</script>
<!--測試請將此處商務通代碼替換為你的-->
<script language="javascript" src="http://dat.zoosnet.net/LR/Chatpre.aspx?id=DAT1111111&float=0&lng=cn"></script>
<!--測試請將此處商務通代碼替換為你的-->
</body>
</html>