1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- var qs = parseQueryString(window.location.href);
- $().ready(function(){
- $(".loading").show();
- init(qs.id?qs.id:'')
- })
- function init(id) {
- $.ajax({
- url:'/api/v2/smzdm/articleshow',
- type:'post',
- data:{
- 'id':id
- },
- success:function (res){
- $(".loading").hide();
- if(res.errno==0) {
- var data=res.rst.data
- $(".title").text(data.title)
- $(".pict").attr("src",data.pic_url)
- var imgReg = /<img.*?(?:>|\/>)/gi;
- var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
- var str=data.count
- var arr=str.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi,function(match,capture){
- // $(match).attr("class")来判断元素的类名
- if(match.indexOf('face')==-1&&match.indexOf('data-ratio')==-1) {
- if(match.indexOf('data-ratio')!=-1) {
- var newStr='<div class="imgCenter">'+match+'</div>'
- return newStr;
- }else {
- var newStr='<div class="imgStr">'+match+'</div>'
- return newStr;
- }
- }else {
- return match;
- }
- });
- $(".article").html(arr)
- $('span').remove('.embed-card-info'); $('span').remove('.embed-card-logo');
- }else {
- showMsg(res.err)
- }
- },
- error:function () {
- $(".loading").hide();
- showMsg('网络异常,请稍后再试')
- }
- })
- }
- // 展示错误提示信息
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.getElementsByTagName("p")[0].innerHTML=msg;
- msgBox.style.display="block";
-
- setTimeout(function() {
- msgBox.style.display="none";
-
- }, 2000);
- }
-
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, function($0, $1, $2) {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
|