[英]how to edit <object> in javascript
I am editing a system and I noticed a weird tag <object>
I tried to search for it but didn't get any luck. 我正在编辑一个系统,我注意到一个奇怪的标签<object>
我试图搜索它,但是没有任何运气。 the code looks something like this : <object width="50" height="10" tabIndex="12345" id="test" classid="ghjkl" />
代码看起来像这样: <object width="50" height="10" tabIndex="12345" id="test" classid="ghjkl" />
so what I need to do is I need to edit the value of this textbox but I didn't get any luck with that. 因此,我需要做的是编辑此文本框的值,但是我对此没有任何运气。 I have tried to grab it by id (and it worked) but I couldn't get the exact value or edit it's value. 我试图通过id来抓取它(并且它起作用了),但是我无法获得确切的值或编辑它的值。 any ideas ? 有任何想法吗 ?
The HTML
<object>
element represents an external resource, which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin. HTML<object>
元素表示外部资源,可以将其视为图像,嵌套的浏览上下文或要由插件处理的资源。
There is no value
attribute for <object>
element. <object>
元素没有value
属性。 Please check MDN link for all the available attributes present in <object>
. 请检查MDN链接以获取<object>
存在的所有可用属性。
But there is data
attribute which you can modify: 但是,您可以修改data
属性:
document.addEventListener('DOMContentLoaded', function(){ document.getElementById('test').setAttribute('data', 'new-movie.swf'); console.log(document.getElementById('test').getAttribute('data')); }, false);
<object width="50" height="10" tabIndex="12345" id="test" classid="ghjkl" data="movie.swf" type="application/x-shockwave-flash"></object>
Hi if you want to get the value from object tag you can use this code. 您好,如果您想从对象标签获取值,可以使用此代码。
HTML HTML
<object width="50" height="10" tabIndex="12345" id="test" classid="ghjkl" />
JavaScript 的JavaScript
var t=document.querySelector("#test");
var htmlDocument= t.contentDocument;
If you have jQuery in your project and want to remove the object element you can use the remove method. 如果您的项目中包含jQuery,并且要删除object元素,则可以使用remove方法。
$("#test").remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.