需要将 <input id="uid" value="6026803" type="hidden" name="uid"> 中的 6026803替换为自己的开通了离线宝的百度推广账户ID
<p>
<form id="lxb-data-form">
<input id="uid" value="6026803" type="hidden" name="uid">
<input id="ttk" type="hidden" name="ttk">
<input style="border:#339933 1px solid;padding:0 5px;width:200px;height:30px;" id="vtel" placeholder="输入电话号码 可请求专家回电..." />
<input style="border:none;background:#339933;height:30px;color:#fff;cursor:pointer;" id="cbBtn" onclick="lxbcb.getTk('vtel','cbBtn',false);" value="免费回拨" type="button" />
</form>
</p>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
(function(){
var tk = '';
var view = {};
view.host = 'http://lxbjs.baidu.com';
function G(id) {
return document.getElementById(id);
}
function get(url, callback) {
jQuery.getJSON(url + "&callback=?",callback);
}
function validateTel(str) {
var res = true;
if (str.charAt(0) == '1') {
res = /^1[3458]d{9}$/.test(str);
}
else {
res = /^0d{9,11}$/.test(str);
}
return res;
};
function telCB() {
if (view.btn.disabled) {
return;
}
var vtel = view.vtel.value;
if (!validateTel(vtel)) {
alert('请您输入正确的号码,手机号码请直接输入,座机请加区号', true);
return false;
}
var form = G('lxb-data-form');
var url = view.host + '/cb/call';
url += '?vtel=' + vtel;
url += '&uid=' + (form.uid ? form.uid.value : '');
url += '&tk=' + tk;
url += '&t=' + (new Date()).getTime();
view.btn.value = '正在回呼...';
view.btn.disabled = true;
get(url, function (dataObj) {
alert(dataObj.msg);
if(0 == dataObj.status){
view.btn.disabled = false;
view.btn.value = '免费电话';
}
});
if (view.storeTel && window.localStorage) {
localStorage.setItem('tel', value);
}
}
function getTk (telId,btnId,storeTel) {
view.storeTel = storeTel;
view.vtel = G(telId);
if(!view.vtel){
alert('在页面中找不到输入框' + telId);
return;
}
view.btn = G(btnId);
if(!view.btn){
alert('在页面中找不到按钮' + btnId);
return;
}
if('' == tk){
var url = view.host + '/cb/user/check';
url += '?f=4&uid=' + (G('lxb-data-form').uid ? G('lxb-data-form').uid.value : '');
url += '&r=' + encodeURIComponent((document.referer ? document.referer : location.href));
url += '&t=' + (new Date()).getTime();
get(url, function (dataObj) {
if(0 == dataObj.status){
G('ttk').value=dataObj.data.tk;
tk = dataObj.data.tk;
telCB();
}else{
view.btn.disabled = true;
}
});
}else{
telCB();
}
if (view.storeTel && window.localStorage) {
var tel = localStorage.getItem('tel');
if (tel) {
view.vtel.value = tel;
}
}
}
if(!window.lxbcb){window['lxbcb']={};}
window['lxbcb']['getTk'] = getTk;
window['lxbcb']['telCB'] = telCB;
})();
</script>