最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery update the object data value dynamically? - Stack Overflow

programmeradmin2浏览0评论

url

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

Js code

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>

What would the syntax be if i want to add the data of the object = filepath

url

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

Js code

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>

What would the syntax be if i want to add the data of the object = filepath

Share Improve this question asked Mar 6, 2013 at 2:06 inputErrorinputError 6103 gold badges13 silver badges28 bronze badges 1
  • $('.divEmbed object').attr('data', filePath);? – Evan Davis Commented Mar 6, 2013 at 2:09
Add a ment  | 

1 Answer 1

Reset to default 4

You're setting jQuery's data object, when in fact what you want is to change an ordinary attribute. Use this instead:

$('.divEmbed object').attr('data', filePath);
发布评论

评论列表(0)

  1. 暂无评论