2013-03-06 42 views
0

网址jquery动态更新对象数据值?

http://localhost/news-events/news.html?file=hosted_service.pdf 

JS代码

parseURL : function() { 
var _path = window.location.pathname; 
console.log(_path); 
var _locationSearch = location.search; 
var _locationParse = _locationSearch.replace('?file=',''); 
console.log(_locationParse); 
var filePath = "/pdffiles/"+_locationParse ; // /pdffiles/hosted_service.pdf 
$('.divEmbed object').data(filePath); **How to set the data of object? this is wrong** 
console.log(filePath); 
} 

的Html

<div class="divEmbed"> 
       <object data="" type="application/pdf"> 
        alt : It appears you don't have a PDF plugin for this browser. 
        Click <a href="">here</a> to Download the file. 
       </object> 
      </div> 

将语法是什么,如果我想添加的对象的数据=文件路径

+0

'$('。divEmbed object')。attr('data',filePath);'? – Mathletics 2013-03-06 02:09:53

回答

1

你正在设置jQuery的数据对象,实际上你想要的是改变一个普通的属性。改为:

$('.divEmbed object').attr('data', filePath); 
+0

工作干杯! – inputError 2013-03-06 02:12:46

+0

它在Firefox中的作品,但不是在铬? – inputError 2013-03-06 02:16:16

+0

没关系它的加载速度非常慢..再次感谢 – inputError 2013-03-06 02:19:50