admin管理员组文章数量:1305179
i dunno but i might be missing something, i've tried a few thigns but they all end up with the same result and i'm about to start pulling my hair out
<script type="text/javascript">
function set_size() {
// Get users Screen Res
var screen_height = screen.height;
var attribute = "height";
var element = "pdfFile";
// Take say 200px off the res to accumulate the browser screen useage
var object_height = screen_height - 200;
// Write to the height attribute
document.getElementById[element].getAttribute[attribute].value = object_height;
document.getElementById['jsoutput'].innerhtml = object_height;
}
</script>
<div class="Contact_list">
<a name="contacts"><object id="pdfFile" data="files/contacts/pdf/contacts.pdf" type="application/pdf" width="100%" height="600" style="border: 1px solid;"></object></a>
<span id="jsoutput"></span>
</div>
<script type="text/javascript">
set_size();
</script>
[12:13:28.050] document.getElementById[element] is undefined @ http://localhost/**/index.php?page=contacts#contacts:57
i dunno but i might be missing something, i've tried a few thigns but they all end up with the same result and i'm about to start pulling my hair out
<script type="text/javascript">
function set_size() {
// Get users Screen Res
var screen_height = screen.height;
var attribute = "height";
var element = "pdfFile";
// Take say 200px off the res to accumulate the browser screen useage
var object_height = screen_height - 200;
// Write to the height attribute
document.getElementById[element].getAttribute[attribute].value = object_height;
document.getElementById['jsoutput'].innerhtml = object_height;
}
</script>
<div class="Contact_list">
<a name="contacts"><object id="pdfFile" data="files/contacts/pdf/contacts.pdf" type="application/pdf" width="100%" height="600" style="border: 1px solid;"></object></a>
<span id="jsoutput"></span>
</div>
<script type="text/javascript">
set_size();
</script>
Share Improve this question asked Jul 4, 2011 at 2:19 cyclobscyclobs 451 silver badge6 bronze badges[12:13:28.050] document.getElementById[element] is undefined @ http://localhost/**/index.php?page=contacts#contacts:57
4 Answers
Reset to default 4Both of these should not be like this:
// Write to the height attribute
document.getElementById[element].getAttribute[attribute].value = object_height;
document.getElementById['jsoutput'].innerhtml = object_height;
but should be like this:
// Write to the height attribute
document.getElementById(element).style.height = object_height;
document.getElementById('jsoutput').style.height = object_height;
getElementById and getAttribute are functions whose parameters goes in parentheses, not in brackets.
Height is set by setting style.height, not setting .value on an attribute.
You generally do NOT set the height on an inline element which a <span>
tag is. You can set the height on a block element or an inline-block element. So, your attempt to set the height on the jsoutput object will probably not do what you want.
Also, the innerHTML attribute must be capitalized as innerHTML, not innerhtml, though you weren't using that attribute correctly anyway so I replaced it with style.height.
getElementById is a function, not an array - call it with () instead of [] around the ID
getElementById(element)not
document.getElementById[element]`.. please verify that...
you must use parenthesis like ( and ) since getElementById is a function and not an object.
document.getElementById(element)
本文标签: javascript quotdocumentgetElementById undefinedquotStack Overflow
版权声明:本文标题:javascript "document.getElementById undefined" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741797989a2398052.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论