2

网址

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 的数据,语法是什么

4

1 回答 1

4

您正在设置 jQuery 的数据对象,而实际上您想要的是更改普通属性。改用这个:

$('.divEmbed object').attr('data', filePath);
于 2013-03-06T02:10:02.020 回答