网址
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>
如果我想添加object = filepath
的数据,语法是什么?答案 0 :(得分:3)
您正在设置jQuery的数据对象,实际上您想要的是更改普通属性。请改用:
$('.divEmbed object').attr('data', filePath);