English 中文(简体)
elementById 返回Safari 中的空或未定义
原标题:getElementById returns null or undefined in Safari

下面是一些框架的代码片断。 我试图在 javascript 中使用 DOM 。 我可以在 FF 和 IE 中使用 < code > 文件。 getElementById( 提高 Confirm) 。 点击( ) < / code > FF 和 IE 中 。 它不会在 safari 中工作 。 我尝试了多种不同的事物, 尝试与 ID 提高Conference 一起进入锚。 它看起来像 < code > 文件。 getElementById () () < /code > 找不到任何元素。 我尝试了 < code > winow. document < /code >, 但当我尝试了 < code < code > < 或 < code < icol > 返回了 < 。 < code/belb > 。

有人能告诉我正确的解决办法吗?

  <form method=​"POST" 
        action=​"somescript.asp?CMD=POST&​TODO=TRUE2" 
        id=​"FORMSV2DISPLAY"
        name=​"FORMSV2DISPLAY">​
    <a id=​"raiseConfirm" href=​"#divConfirm" class=​"nyroModal">HERE IT IS​</a> 
    <div id="divConfirm" style=​"display:​none;​">​…​</div>​ 
最佳回答

我之前试着说这个,它贴的很奇怪。我用JQuery解决了这个问题,这就是我所做的。

      $("#raiseConfirm").trigger("click");
问题回答

您可以使用 jquery:

$( #raiseConfirm )

It will surely work on all browsers. That s the magic of jquery :)

如果您想要附加到单击事件上 :

$(document).ready(function () {
    $("#raiseConfirm").click(doSomenthing);
});

var doSomenthing = function () {
    /* Something I do here */
}

document.getElementById() will not work in safari. Instead you need to use document.all... Therefore, JQuery comes into picture where it is supported by all browsers. This can be the major difference between Javascript and JQuery where to be used.

我在JSFiddle尝试过这个 没有jQuery 我无法让它在Safari工作

http://jsfidle.net/belthasar/Zct4S/" rel="nofollow">http://jsfidle.net/belthasar/Zct4S/





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签