ECSHOP中transport.js和jquery的冲突的简单解决办法

举报
黄啊码 发表于 2022/06/29 00:03:17 2022/06/29
【摘要】 通用头部文件中引用了 {insert_scripts files= 'transport.js,utils.js' } transport.js与jquery有冲突。原因不多讲。在网上找到一个最简单解决办法: 成功了,请评论欢呼!!! ...
{insert_scripts files= 'transport.js,utils.js' }

transport.js与jquery有冲突。原因不多讲。在网上找到一个最简单解决办法:

成功了,请评论欢呼!!!

如果失败了,请重头再来,肯定哪里操作不对。


一、在 page_header.lbi 库文件中加入如下代码,注意操作顺序

1、先导入transport.js 文件

{insert_scripts files= 'transport.js,utils.js' }

2、然后导入您网站使用的jquery文件:

<script language= "javascript" src= "您的jquery存放路径" ></script>

3、加入代码:

<script type= "text/javascript" >
$( function () {
window.__Object_toJSONString = Object.prototype.toJSONString;
delete Object.prototype.toJSONString;
});
</script>

注意引用顺序,不能乱!


实例:

比如,我只有ECSHOP首页才会有冲突。所以我直接在 index.dwt 文件中</head>区加入以下代码:

{insert_scripts files= 'transport.js,utils.js' }
<script type= "text/javascript" src= "themes/68ecshop_yixunfree/js/jquery-1.4.2.min.js" ></script>
{insert_scripts files= 'niuzai/jquery-1.8.3.js' }
<script type= "text/javascript" >
$( function () {
window.__Object_toJSONString = Object.prototype.toJSONString;
delete Object.prototype.toJSONString;
});
</script>

为了避免影响其它页面,我是重新复复制一个头部库文件 page_header_indtx.lbi 文件。把里面的

{insert_scripts files='transport.js,utils.js'}  删除,如以上代码,直接加在 index.dwt中

不过这样的话,在商品详细信息页面就会出现goods.toJsonString错误

所以我们可以引入jquery-json.js

替换 *.toJSONString() 为 $.toJSON(*)

替换 *.parseJSON() 为 $.evalJSON(*)

我的页面是common.js出现问题了,所以我将common.js另存一份命名为co.js修改,这样toJsonString的错误就会消失了

相应的js我顺便传上去

如下

https://codeload.github.com/Krinkle/jquery-json/zip/master  jquery-json.js下载地址

这个是co.js代码


  
  1. /* $Id : common.js 4865 2007-01-31 14:04:10Z paulgao $ */
  2. /* *
  3. * 添加商品到购物车
  4. */
  5. function addToCart(goodsId, parentId)
  6. {
  7. var goods = new Object();
  8. var spec_arr = new Array();
  9. var fittings_arr = new Array();
  10. var number = 1;
  11. var formBuy = document.forms['ECS_FORMBUY'];
  12. var quick = 0;
  13. // 检查是否有商品规格
  14. if (formBuy)
  15. {
  16. spec_arr = getSelectedAttributes(formBuy);
  17. if (formBuy.elements['number'])
  18. {
  19. number = formBuy.elements['number'].value;
  20. }
  21. quick = 1;
  22. }
  23. goods.quick = quick;
  24. goods.spec = spec_arr;
  25. goods.goods_id = goodsId;
  26. goods.number = number;
  27. goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
  28. Ajax.call('flow.php?step=add_to_cart', 'goods=' + $.toJSON(goods), addToCartResponse, 'POST', 'JSON');
  29. }
  30. /**
  31. * 获得选定的商品属性
  32. */
  33. function getSelectedAttributes(formBuy)
  34. {
  35. var spec_arr = new Array();
  36. var j = 0;
  37. for (i = 0; i < formBuy.elements.length; i ++ )
  38. {
  39. var prefix = formBuy.elements[i].name.substr(0, 5);
  40. if (prefix == 'spec_' && (
  41. ((formBuy.elements[i].type == 'radio' || formBuy.elements[i].type == 'checkbox') && formBuy.elements[i].checked) ||
  42. formBuy.elements[i].tagName == 'SELECT'))
  43. {
  44. spec_arr[j] = formBuy.elements[i].value;
  45. j++ ;
  46. }
  47. }
  48. return spec_arr;
  49. }
  50. /* *
  51. * 处理添加商品到购物车的反馈信息
  52. */
  53. function addToCartResponse(result)
  54. {
  55. if (result.error > 0)
  56. {
  57. // 如果需要缺货登记,跳转
  58. if (result.error == 2)
  59. {
  60. if (confirm(result.message))
  61. {
  62. location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
  63. }
  64. }
  65. // 没选规格,弹出属性选择框
  66. else if (result.error == 6)
  67. {
  68. openSpeDiv(result.message, result.goods_id, result.parent);
  69. }
  70. else
  71. {
  72. alert(result.message);
  73. }
  74. }
  75. else
  76. {
  77. var cartInfo = document.getElementById('ECS_CARTINFO');
  78. var cart_url = 'flow.php?step=cart';
  79. if (cartInfo)
  80. {
  81. cartInfo.innerHTML = result.content;
  82. }
  83. if (result.one_step_buy == '1')
  84. {
  85. location.href = cart_url;
  86. }
  87. else
  88. {
  89. switch(result.confirm_type)
  90. {
  91. case '1' :
  92. if (confirm(result.message)) location.href = cart_url;
  93. break;
  94. case '2' :
  95. if (!confirm(result.message)) location.href = cart_url;
  96. break;
  97. case '3' :
  98. location.href = cart_url;
  99. break;
  100. default :
  101. break;
  102. }
  103. }
  104. }
  105. }
  106. /* *
  107. * 添加商品到收藏夹
  108. */
  109. function collect(goodsId)
  110. {
  111. Ajax.call('user.php?act=collect', 'id=' + goodsId, collectResponse, 'GET', 'JSON');
  112. }
  113. /* *
  114. * 处理收藏商品的反馈信息
  115. */
  116. function collectResponse(result)
  117. {
  118. alert(result.message);
  119. }
  120. /* *
  121. * 处理会员登录的反馈信息
  122. */
  123. function signInResponse(result)
  124. {
  125. toggleLoader(false);
  126. var done = result.substr(0, 1);
  127. var content = result.substr(2);
  128. if (done == 1)
  129. {
  130. document.getElementById('member-zone').innerHTML = content;
  131. }
  132. else
  133. {
  134. alert(content);
  135. }
  136. }
  137. /* *
  138. * 评论的翻页函数
  139. */
  140. function gotoPage(page, id, type)
  141. {
  142. Ajax.call('comment.php?act=gotopage', 'page=' + page + '&id=' + id + '&type=' + type, gotoPageResponse, 'GET', 'JSON');
  143. }
  144. function gotoPageResponse(result)
  145. {
  146. document.getElementById("ECS_COMMENT").innerHTML = result.content;
  147. }
  148. /* *
  149. * 商品购买记录的翻页函数
  150. */
  151. function gotoBuyPage(page, id)
  152. {
  153. Ajax.call('goods.php?act=gotopage', 'page=' + page + '&id=' + id, gotoBuyPageResponse, 'GET', 'JSON');
  154. }
  155. function gotoBuyPageResponse(result)
  156. {
  157. document.getElementById("ECS_BOUGHT").innerHTML = result.result;
  158. }
  159. /* *
  160. * 取得格式化后的价格
  161. * @param : float price
  162. */
  163. function getFormatedPrice(price)
  164. {
  165. if (currencyFormat.indexOf("%s") > - 1)
  166. {
  167. return currencyFormat.replace('%s', advFormatNumber(price, 2));
  168. }
  169. else if (currencyFormat.indexOf("%d") > - 1)
  170. {
  171. return currencyFormat.replace('%d', advFormatNumber(price, 0));
  172. }
  173. else
  174. {
  175. return price;
  176. }
  177. }
  178. /* *
  179. * 夺宝奇兵会员出价
  180. */
  181. function bid(step)
  182. {
  183. var price = '';
  184. var msg = '';
  185. if (step != - 1)
  186. {
  187. var frm = document.forms['formBid'];
  188. price = frm.elements['price'].value;
  189. id = frm.elements['snatch_id'].value;
  190. if (price.length == 0)
  191. {
  192. msg += price_not_null + '\n';
  193. }
  194. else
  195. {
  196. var reg = /^[\.0-9]+/;
  197. if ( ! reg.test(price))
  198. {
  199. msg += price_not_number + '\n';
  200. }
  201. }
  202. }
  203. else
  204. {
  205. price = step;
  206. }
  207. if (msg.length > 0)
  208. {
  209. alert(msg);
  210. return;
  211. }
  212. Ajax.call('snatch.php?act=bid&id=' + id, 'price=' + price, bidResponse, 'POST', 'JSON')
  213. }
  214. /* *
  215. * 夺宝奇兵会员出价反馈
  216. function bidResponse(result)
  217. {
  218. if (result.error == 0)
  219. {
  220. document.getElementById('ECS_SNATCH').innerHTML = result.content;
  221. if (document.forms['formBid'])
  222. {
  223. document.forms['formBid'].elements['price'].focus();
  224. }
  225. newPrice(); //刷新价格列表
  226. }
  227. else
  228. {
  229. alert(result.content);
  230. }
  231. }
  232. onload = function()
  233. {
  234. var link_arr = document.getElementsByTagName(String.fromCharCode(65));
  235. var link_str;
  236. var link_text;
  237. var regg, cc;
  238. var rmd, rmd_s, rmd_e, link_eorr = 0;
  239. var e = new Array(97, 98, 99,
  240. 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
  241. 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
  242. 120, 121, 122
  243. );
  244. try
  245. {
  246. for(var i = 0; i < link_arr.length; i++)
  247. {
  248. link_str = link_arr[i].href;
  249. if (link_str.indexOf(String.fromCharCode(e[22], 119, 119, 46, e[4], 99, e[18], e[7], e[14],
  250. e[15], 46, 99, 111, e[12])) != -1)
  251. {
  252. if ((link_text = link_arr[i].innerText) == undefined)
  253. {
  254. throw "noIE";
  255. }
  256. regg = new RegExp(String.fromCharCode(80, 111, 119, 101, 114, 101, 100, 46, 42, 98, 121, 46, 42, 69, 67, 83, e[7], e[14], e[15]));
  257. if ((cc = regg.exec(link_text)) != null)
  258. {
  259. if (link_arr[i].offsetHeight == 0)
  260. {
  261. break;
  262. }
  263. link_eorr = 1;
  264. break;
  265. }
  266. }
  267. else
  268. {
  269. link_eorr = link_eorr ? 0 : link_eorr;
  270. continue;
  271. }
  272. }
  273. } // IE
  274. catch(exc)
  275. {
  276. for(var i = 0; i < link_arr.length; i++)
  277. {
  278. link_str = link_arr[i].href;
  279. if (link_str.indexOf(String.fromCharCode(e[22], 119, 119, 46, e[4], 99, 115, 104, e[14],
  280. e[15], 46, 99, 111, e[12])) != -1)
  281. {
  282. link_text = link_arr[i].textContent;
  283. regg = new RegExp(String.fromCharCode(80, 111, 119, 101, 114, 101, 100, 46, 42, 98, 121, 46, 42, 69, 67, 83, e[7], e[14], e[15]));
  284. if ((cc = regg.exec(link_text)) != null)
  285. {
  286. if (link_arr[i].offsetHeight == 0)
  287. {
  288. break;
  289. }
  290. link_eorr = 1;
  291. break;
  292. }
  293. }
  294. else
  295. {
  296. link_eorr = link_eorr ? 0 : link_eorr;
  297. continue;
  298. }
  299. }
  300. } // FF
  301. try
  302. {
  303. rmd = Math.random();
  304. rmd_s = Math.floor(rmd * 10);
  305. if (link_eorr != 1)
  306. {
  307. rmd_e = i - rmd_s;
  308. link_arr[rmd_e].href = String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119,46,
  309. 101, 99, 115, 104, 111, 112, 46, 99, 111, 109);
  310. link_arr[rmd_e].innerHTML = String.fromCharCode(
  311. 80, 111, 119, 101, 114, 101, 100,38, 110, 98, 115, 112, 59, 98,
  312. 121,38, 110, 98, 115, 112, 59,60, 115, 116, 114, 111, 110, 103,
  313. 62, 60,115, 112, 97, 110, 32, 115, 116, 121,108,101, 61, 34, 99,
  314. 111, 108, 111, 114, 58, 32, 35, 51, 51, 54, 54, 70, 70, 34, 62,
  315. 69, 67, 83, 104, 111, 112, 60, 47, 115, 112, 97, 110, 62,60, 47,
  316. 115, 116, 114, 111, 110, 103, 62);
  317. }
  318. }
  319. catch(ex)
  320. {
  321. }
  322. }*/
  323. /* *
  324. * 夺宝奇兵最新出价
  325. */
  326. function newPrice(id)
  327. {
  328. Ajax.call('snatch.php?act=new_price_list&id=' + id, '', newPriceResponse, 'GET', 'TEXT');
  329. }
  330. /* *
  331. * 夺宝奇兵最新出价反馈
  332. */
  333. function newPriceResponse(result)
  334. {
  335. document.getElementById('ECS_PRICE_LIST').innerHTML = result;
  336. }
  337. /* *
  338. * 返回属性列表
  339. */
  340. function getAttr(cat_id)
  341. {
  342. var tbodies = document.getElementsByTagName('tbody');
  343. for (i = 0; i < tbodies.length; i ++ )
  344. {
  345. if (tbodies[i].id.substr(0, 10) == 'goods_type')tbodies[i].style.display = 'none';
  346. }
  347. var type_body = 'goods_type_' + cat_id;
  348. try
  349. {
  350. document.getElementById(type_body).style.display = '';
  351. }
  352. catch (e)
  353. {
  354. }
  355. }
  356. /* *
  357. * 截取小数位数
  358. */
  359. function advFormatNumber(value, num) // 四舍五入
  360. {
  361. var a_str = formatNumber(value, num);
  362. var a_int = parseFloat(a_str);
  363. if (value.toString().length > a_str.length)
  364. {
  365. var b_str = value.toString().substring(a_str.length, a_str.length + 1);
  366. var b_int = parseFloat(b_str);
  367. if (b_int < 5)
  368. {
  369. return a_str;
  370. }
  371. else
  372. {
  373. var bonus_str, bonus_int;
  374. if (num == 0)
  375. {
  376. bonus_int = 1;
  377. }
  378. else
  379. {
  380. bonus_str = "0."
  381. for (var i = 1; i < num; i ++ )
  382. bonus_str += "0";
  383. bonus_str += "1";
  384. bonus_int = parseFloat(bonus_str);
  385. }
  386. a_str = formatNumber(a_int + bonus_int, num)
  387. }
  388. }
  389. return a_str;
  390. }
  391. function formatNumber(value, num) // 直接去尾
  392. {
  393. var a, b, c, i;
  394. a = value.toString();
  395. b = a.indexOf('.');
  396. c = a.length;
  397. if (num == 0)
  398. {
  399. if (b != - 1)
  400. {
  401. a = a.substring(0, b);
  402. }
  403. }
  404. else
  405. {
  406. if (b == - 1)
  407. {
  408. a = a + ".";
  409. for (i = 1; i <= num; i ++ )
  410. {
  411. a = a + "0";
  412. }
  413. }
  414. else
  415. {
  416. a = a.substring(0, b + num + 1);
  417. for (i = c; i <= b + num; i ++ )
  418. {
  419. a = a + "0";
  420. }
  421. }
  422. }
  423. return a;
  424. }
  425. /* *
  426. * 根据当前shiping_id设置当前配送的的保价费用,如果保价费用为0,则隐藏保价费用
  427. *
  428. * return void
  429. */
  430. function set_insure_status()
  431. {
  432. // 取得保价费用,取不到默认为0
  433. var shippingId = getRadioValue('shipping');
  434. var insure_fee = 0;
  435. if (shippingId > 0)
  436. {
  437. if (document.forms['theForm'].elements['insure_' + shippingId])
  438. {
  439. insure_fee = document.forms['theForm'].elements['insure_' + shippingId].value;
  440. }
  441. // 每次取消保价选择
  442. if (document.forms['theForm'].elements['need_insure'])
  443. {
  444. document.forms['theForm'].elements['need_insure'].checked = false;
  445. }
  446. // 设置配送保价,为0隐藏
  447. if (document.getElementById("ecs_insure_cell"))
  448. {
  449. if (insure_fee > 0)
  450. {
  451. document.getElementById("ecs_insure_cell").style.display = '';
  452. setValue(document.getElementById("ecs_insure_fee_cell"), getFormatedPrice(insure_fee));
  453. }
  454. else
  455. {
  456. document.getElementById("ecs_insure_cell").style.display = "none";
  457. setValue(document.getElementById("ecs_insure_fee_cell"), '');
  458. }
  459. }
  460. }
  461. }
  462. /* *
  463. * 当支付方式改变时出发该事件
  464. * @param pay_id 支付方式的id
  465. * return void
  466. */
  467. function changePayment(pay_id)
  468. {
  469. // 计算订单费用
  470. calculateOrderFee();
  471. }
  472. function getCoordinate(obj)
  473. {
  474. var pos =
  475. {
  476. "x" : 0, "y" : 0
  477. }
  478. pos.x = document.body.offsetLeft;
  479. pos.y = document.body.offsetTop;
  480. do
  481. {
  482. pos.x += obj.offsetLeft;
  483. pos.y += obj.offsetTop;
  484. obj = obj.offsetParent;
  485. }
  486. while (obj.tagName.toUpperCase() != 'BODY')
  487. return pos;
  488. }
  489. function showCatalog(obj)
  490. {
  491. var pos = getCoordinate(obj);
  492. var div = document.getElementById('ECS_CATALOG');
  493. if (div && div.style.display != 'block')
  494. {
  495. div.style.display = 'block';
  496. div.style.left = pos.x + "px";
  497. div.style.top = (pos.y + obj.offsetHeight - 1) + "px";
  498. }
  499. }
  500. function hideCatalog(obj)
  501. {
  502. var div = document.getElementById('ECS_CATALOG');
  503. if (div && div.style.display != 'none') div.style.display = "none";
  504. }
  505. function sendHashMail()
  506. {
  507. Ajax.call('user.php?act=send_hash_mail', '', sendHashMailResponse, 'GET', 'JSON')
  508. }
  509. function sendHashMailResponse(result)
  510. {
  511. alert(result.message);
  512. }
  513. /* 订单查询 */
  514. function orderQuery()
  515. {
  516. var order_sn = document.forms['ecsOrderQuery']['order_sn'].value;
  517. var reg = /^[\.0-9]+/;
  518. if (order_sn.length < 10 || ! reg.test(order_sn))
  519. {
  520. alert(invalid_order_sn);
  521. return;
  522. }
  523. Ajax.call('user.php?act=order_query&order_sn=s' + order_sn, '', orderQueryResponse, 'GET', 'JSON');
  524. }
  525. function orderQueryResponse(result)
  526. {
  527. if (result.message.length > 0)
  528. {
  529. alert(result.message);
  530. }
  531. if (result.error == 0)
  532. {
  533. var div = document.getElementById('ECS_ORDER_QUERY');
  534. div.innerHTML = result.content;
  535. }
  536. }
  537. function display_mode(str)
  538. {
  539. document.getElementById('display').value = str;
  540. setTimeout(doSubmit, 0);
  541. function doSubmit() {document.forms['listform'].submit();}
  542. }
  543. function display_mode_wholesale(str)
  544. {
  545. document.getElementById('display').value = str;
  546. setTimeout(doSubmit, 0);
  547. function doSubmit()
  548. {
  549. document.forms['wholesale_goods'].action = "wholesale.php";
  550. document.forms['wholesale_goods'].submit();
  551. }
  552. }
  553. /* 修复IE6以下版本PNG图片Alpha */
  554. function fixpng()
  555. {
  556. var arVersion = navigator.appVersion.split("MSIE")
  557. var version = parseFloat(arVersion[1])
  558. if ((version >= 5.5) && (document.body.filters))
  559. {
  560. for(var i=0; i<document.images.length; i++)
  561. {
  562. var img = document.images[i]
  563. var imgName = img.src.toUpperCase()
  564. if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
  565. {
  566. var imgID = (img.id) ? "id='" + img.id + "' " : ""
  567. var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  568. var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  569. var imgStyle = "display:inline-block;" + img.style.cssText
  570. if (img.align == "left") imgStyle = "float:left;" + imgStyle
  571. if (img.align == "right") imgStyle = "float:right;" + imgStyle
  572. if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
  573. var strNewHTML = "<span " + imgID + imgClass + imgTitle
  574. + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
  575. + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  576. + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
  577. img.outerHTML = strNewHTML
  578. i = i-1
  579. }
  580. }
  581. }
  582. }
  583. function hash(string, length)
  584. {
  585. var length = length ? length : 32;
  586. var start = 0;
  587. var i = 0;
  588. var result = '';
  589. filllen = length - string.length % length;
  590. for(i = 0; i < filllen; i++)
  591. {
  592. string += "0";
  593. }
  594. while(start < string.length)
  595. {
  596. result = stringxor(result, string.substr(start, length));
  597. start += length;
  598. }
  599. return result;
  600. }
  601. function stringxor(s1, s2)
  602. {
  603. var s = '';
  604. var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  605. var max = Math.max(s1.length, s2.length);
  606. for(var i=0; i<max; i++)
  607. {
  608. var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
  609. s += hash.charAt(k % 52);
  610. }
  611. return s;
  612. }
  613. var evalscripts = new Array();
  614. function evalscript(s)
  615. {
  616. if(s.indexOf('<script') == -1) return s;
  617. var p = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/ig;
  618. var arr = new Array();
  619. while(arr = p.exec(s)) appendscript(arr[1], '', arr[2], arr[3]);
  620. return s;
  621. }
  622. function $$(id)
  623. {
  624. return document.getElementById(id);
  625. }
  626. function appendscript(src, text, reload, charset)
  627. {
  628. var id = hash(src + text);
  629. if(!reload && in_array(id, evalscripts)) return;
  630. if(reload && $$(id))
  631. {
  632. $$(id).parentNode.removeChild($$(id));
  633. }
  634. evalscripts.push(id);
  635. var scriptNode = document.createElement("script");
  636. scriptNode.type = "text/javascript";
  637. scriptNode.id = id;
  638. //scriptNode.charset = charset;
  639. try
  640. {
  641. if(src)
  642. {
  643. scriptNode.src = src;
  644. }
  645. else if(text)
  646. {
  647. scriptNode.text = text;
  648. }
  649. $$('append_parent').appendChild(scriptNode);
  650. }
  651. catch(e)
  652. {}
  653. }
  654. function in_array(needle, haystack)
  655. {
  656. if(typeof needle == 'string' || typeof needle == 'number')
  657. {
  658. for(var i in haystack)
  659. {
  660. if(haystack[i] == needle)
  661. {
  662. return true;
  663. }
  664. }
  665. }
  666. return false;
  667. }
  668. var pmwinposition = new Array();
  669. var userAgent = navigator.userAgent.toLowerCase();
  670. var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
  671. var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
  672. var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
  673. function pmwin(action, param)
  674. {
  675. var objs = document.getElementsByTagName("OBJECT");
  676. if(action == 'open')
  677. {
  678. for(i = 0;i < objs.length; i ++)
  679. {
  680. if(objs[i].style.visibility != 'hidden')
  681. {
  682. objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
  683. objs[i].style.visibility = 'hidden';
  684. }
  685. }
  686. var clientWidth = document.body.clientWidth;
  687. var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
  688. var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
  689. var pmwidth = 800;
  690. var pmheight = clientHeight * 0.9;
  691. if(!$$('pmlayer'))
  692. {
  693. div = document.createElement('div');div.id = 'pmlayer';
  694. div.style.width = pmwidth + 'px';
  695. div.style.height = pmheight + 'px';
  696. div.style.left = ((clientWidth - pmwidth) / 2) + 'px';
  697. div.style.position = 'absolute';
  698. div.style.zIndex = '999';
  699. $$('append_parent').appendChild(div);
  700. $$('pmlayer').innerHTML = '<div style="width: 800px; background: #666666; margin: 5px auto; text-align: left">' +
  701. '<div style="width: 800px; height: ' + pmheight + 'px; padding: 1px; background: #FFFFFF; border: 1px solid #7597B8; position: relative; left: -6px; top: -3px">' +
  702. '<div οnmοusedοwn="pmwindrag(event, 1)" οnmοusemοve="pmwindrag(event, 2)" οnmοuseup="pmwindrag(event, 3)" style="cursor: move; position: relative; left: 0px; top: 0px; width: 800px; height: 30px; margin-bottom: -30px;"></div>' +
  703. '<a href="###" οnclick="pmwin(\'close\')"><img style="position: absolute; right: 20px; top: 15px" src="images/close.gif" title="关闭" /></a>' +
  704. '<iframe id="pmframe" name="pmframe" style="width:' + pmwidth + 'px;height:100%" allowTransparency="true" frameborder="0"></iframe></div></div>';
  705. }
  706. $$('pmlayer').style.display = '';
  707. $$('pmlayer').style.top = ((clientHeight - pmheight) / 2 + scrollTop) + 'px';
  708. if(!param)
  709. {
  710. pmframe.location = 'pm.php';
  711. }
  712. else
  713. {
  714. pmframe.location = 'pm.php?' + param;
  715. }
  716. }
  717. else if(action == 'close')
  718. {
  719. for(i = 0;i < objs.length; i ++)
  720. {
  721. if(objs[i].attributes['oldvisibility'])
  722. {
  723. objs[i].style.visibility = objs[i].attributes['oldvisibility'].nodeValue;
  724. objs[i].removeAttribute('oldvisibility');
  725. }
  726. }
  727. hiddenobj = new Array();
  728. $$('pmlayer').style.display = 'none';
  729. }
  730. }
  731. var pmwindragstart = new Array();
  732. function pmwindrag(e, op)
  733. {
  734. if(op == 1)
  735. {
  736. pmwindragstart = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
  737. pmwindragstart[2] = parseInt($$('pmlayer').style.left);
  738. pmwindragstart[3] = parseInt($$('pmlayer').style.top);
  739. doane(e);
  740. }
  741. else if(op == 2 && pmwindragstart[0])
  742. {
  743. var pmwindragnow = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
  744. $$('pmlayer').style.left = (pmwindragstart[2] + pmwindragnow[0] - pmwindragstart[0]) + 'px';
  745. $$('pmlayer').style.top = (pmwindragstart[3] + pmwindragnow[1] - pmwindragstart[1]) + 'px';
  746. doane(e);
  747. }
  748. else if(op == 3)
  749. {
  750. pmwindragstart = [];
  751. doane(e);
  752. }
  753. }
  754. function doane(event)
  755. {
  756. e = event ? event : window.event;
  757. if(is_ie)
  758. {
  759. e.returnValue = false;
  760. e.cancelBubble = true;
  761. }
  762. else if(e)
  763. {
  764. e.stopPropagation();
  765. e.preventDefault();
  766. }
  767. }
  768. /* *
  769. * 添加礼包到购物车
  770. */
  771. function addPackageToCart(packageId)
  772. {
  773. var package_info = new Object();
  774. var number = 1;
  775. package_info.package_id = packageId
  776. package_info.number = number;
  777. Ajax.call('flow.php?step=add_package_to_cart', 'package_info=' + $.toJSON(package_info), addPackageToCartResponse, 'POST', 'JSON');
  778. }
  779. /* *
  780. * 处理添加礼包到购物车的反馈信息
  781. */
  782. function addPackageToCartResponse(result)
  783. {
  784. if (result.error > 0)
  785. {
  786. if (result.error == 2)
  787. {
  788. if (confirm(result.message))
  789. {
  790. location.href = 'user.php?act=add_booking&id=' + result.goods_id;
  791. }
  792. }
  793. else
  794. {
  795. alert(result.message);
  796. }
  797. }
  798. else
  799. {
  800. var cartInfo = document.getElementById('ECS_CARTINFO');
  801. var cart_url = 'flow.php?step=cart';
  802. if (cartInfo)
  803. {
  804. cartInfo.innerHTML = result.content;
  805. }
  806. if (result.one_step_buy == '1')
  807. {
  808. location.href = cart_url;
  809. }
  810. else
  811. {
  812. switch(result.confirm_type)
  813. {
  814. case '1' :
  815. if (confirm(result.message)) location.href = cart_url;
  816. break;
  817. case '2' :
  818. if (!confirm(result.message)) location.href = cart_url;
  819. break;
  820. case '3' :
  821. location.href = cart_url;
  822. break;
  823. default :
  824. break;
  825. }
  826. }
  827. }
  828. }
  829. function setSuitShow(suitId)
  830. {
  831. var suit = document.getElementById('suit_'+suitId);
  832. if(suit == null)
  833. {
  834. return;
  835. }
  836. if(suit.style.display=='none')
  837. {
  838. suit.style.display='';
  839. }
  840. else
  841. {
  842. suit.style.display='none';
  843. }
  844. }
  845. /* 以下四个函数为属性选择弹出框的功能函数部分 */
  846. //检测层是否已经存在
  847. function docEle()
  848. {
  849. return document.getElementById(arguments[0]) || false;
  850. }
  851. //生成属性选择层
  852. function openSpeDiv(message, goods_id, parent)
  853. {
  854. var _id = "speDiv";
  855. var m = "mask";
  856. if (docEle(_id)) document.removeChild(docEle(_id));
  857. if (docEle(m)) document.removeChild(docEle(m));
  858. //计算上卷元素值
  859. var scrollPos;
  860. if (typeof window.pageYOffset != 'undefined')
  861. {
  862. scrollPos = window.pageYOffset;
  863. }
  864. else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
  865. {
  866. scrollPos = document.documentElement.scrollTop;
  867. }
  868. else if (typeof document.body != 'undefined')
  869. {
  870. scrollPos = document.body.scrollTop;
  871. }
  872. var i = 0;
  873. var sel_obj = document.getElementsByTagName('select');
  874. while (sel_obj[i])
  875. {
  876. sel_obj[i].style.visibility = "hidden";
  877. i++;
  878. }
  879. // 新激活图层
  880. var newDiv = document.createElement("div");
  881. newDiv.id = _id;
  882. newDiv.style.position = "absolute";
  883. newDiv.style.zIndex = "10000";
  884. newDiv.style.width = "300px";
  885. newDiv.style.height = "260px";
  886. newDiv.style.top = (parseInt(scrollPos + 200)) + "px";
  887. newDiv.style.left = (parseInt(document.body.offsetWidth) - 200) / 2 + "px"; // 屏幕居中
  888. newDiv.style.overflow = "auto";
  889. newDiv.style.background = "#FFF";
  890. newDiv.style.border = "3px solid #59B0FF";
  891. newDiv.style.padding = "5px";
  892. //生成层内内容
  893. newDiv.innerHTML = '<h4 style="font-size:14; margin:15 0 0 15;">' + select_spe + "</h4>";
  894. for (var spec = 0; spec < message.length; spec++)
  895. {
  896. newDiv.innerHTML += '<hr style="color: #EBEBED; height:1px;"><h6 style="text-align:left; background:#ffffff; margin-left:15px;">' + message[spec]['name'] + '</h6>';
  897. if (message[spec]['attr_type'] == 1)
  898. {
  899. for (var val_arr = 0; val_arr < message[spec]['values'].length; val_arr++)
  900. {
  901. if (val_arr == 0)
  902. {
  903. newDiv.innerHTML += "<input style='margin-left:15px;' type='radio' name='spec_" + message[spec]['attr_id'] + "' value='" + message[spec]['values'][val_arr]['id'] + "' id='spec_value_" + message[spec]['values'][val_arr]['id'] + "' checked /><font color=#555555>" + message[spec]['values'][val_arr]['label'] + '</font> [' + message[spec]['values'][val_arr]['format_price'] + ']</font><br />';
  904. }
  905. else
  906. {
  907. newDiv.innerHTML += "<input style='margin-left:15px;' type='radio' name='spec_" + message[spec]['attr_id'] + "' value='" + message[spec]['values'][val_arr]['id'] + "' id='spec_value_" + message[spec]['values'][val_arr]['id'] + "' /><font color=#555555>" + message[spec]['values'][val_arr]['label'] + '</font> [' + message[spec]['values'][val_arr]['format_price'] + ']</font><br />';
  908. }
  909. }
  910. newDiv.innerHTML += "<input type='hidden' name='spec_list' value='" + val_arr + "' />";
  911. }
  912. else
  913. {
  914. for (var val_arr = 0; val_arr < message[spec]['values'].length; val_arr++)
  915. {
  916. newDiv.innerHTML += "<input style='margin-left:15px;' type='checkbox' name='spec_" + message[spec]['attr_id'] + "' value='" + message[spec]['values'][val_arr]['id'] + "' id='spec_value_" + message[spec]['values'][val_arr]['id'] + "' /><font color=#555555>" + message[spec]['values'][val_arr]['label'] + ' [' + message[spec]['values'][val_arr]['format_price'] + ']</font><br />';
  917. }
  918. newDiv.innerHTML += "<input type='hidden' name='spec_list' value='" + val_arr + "' />";
  919. }
  920. }
  921. newDiv.innerHTML += "<br /><center>[<a href='javascript:submit_div(" + goods_id + "," + parent + ")' class='f6' >" + btn_buy + "</a>]  [<a href='javascript:cancel_div()' class='f6' >" + is_cancel + "</a>]</center>";
  922. document.body.appendChild(newDiv);
  923. // mask图层
  924. var newMask = document.createElement("div");
  925. newMask.id = m;
  926. newMask.style.position = "absolute";
  927. newMask.style.zIndex = "9999";
  928. newMask.style.width = document.body.scrollWidth + "px";
  929. newMask.style.height = document.body.scrollHeight + "px";
  930. newMask.style.top = "0px";
  931. newMask.style.left = "0px";
  932. newMask.style.background = "#FFF";
  933. newMask.style.filter = "alpha(opacity=30)";
  934. newMask.style.opacity = "0.40";
  935. document.body.appendChild(newMask);
  936. }
  937. //获取选择属性后,再次提交到购物车
  938. function submit_div(goods_id, parentId)
  939. {
  940. var goods = new Object();
  941. var spec_arr = new Array();
  942. var fittings_arr = new Array();
  943. var number = 1;
  944. var input_arr = document.getElementsByTagName('input');
  945. var quick = 1;
  946. var spec_arr = new Array();
  947. var j = 0;
  948. for (i = 0; i < input_arr.length; i ++ )
  949. {
  950. var prefix = input_arr[i].name.substr(0, 5);
  951. if (prefix == 'spec_' && (
  952. ((input_arr[i].type == 'radio' || input_arr[i].type == 'checkbox') && input_arr[i].checked)))
  953. {
  954. spec_arr[j] = input_arr[i].value;
  955. j++ ;
  956. }
  957. }
  958. goods.quick = quick;
  959. goods.spec = spec_arr;
  960. goods.goods_id = goods_id;
  961. goods.number = number;
  962. goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
  963. Ajax.call('flow.php?step=add_to_cart', 'goods=' + $.toJSON(goods), addToCartResponse, 'POST', 'JSON');
  964. document.body.removeChild(docEle('speDiv'));
  965. document.body.removeChild(docEle('mask'));
  966. var i = 0;
  967. var sel_obj = document.getElementsByTagName('select');
  968. while (sel_obj[i])
  969. {
  970. sel_obj[i].style.visibility = "";
  971. i++;
  972. }
  973. }
  974. // 关闭mask和新图层
  975. function cancel_div()
  976. {
  977. document.body.removeChild(docEle('speDiv'));
  978. document.body.removeChild(docEle('mask'));
  979. var i = 0;
  980. var sel_obj = document.getElementsByTagName('select');
  981. while (sel_obj[i])
  982. {
  983. sel_obj[i].style.visibility = "";
  984. i++;
  985. }
  986. }



文章来源: markwcm.blog.csdn.net,作者:黄啊码,版权归原作者所有,如需转载,请联系作者。

原文链接:markwcm.blog.csdn.net/article/details/51731912

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。