English 中文(简体)
• 如何阻挡页 w
原标题:how to block the page width javascript
  • 时间:2012-05-13 05:29:22
  •  标签:
  • javascript
...
<head>
    <script type="text/javascript" src="a.js"></script>
</head>
<body>
    <button id="test">click me</button>
    <script type="text/javascript">
        show();
        document.getElementById( test ).onclick=function(){
            show();
        }
    </script>
</body>
</html>

the code above:

我将<代码>a.js载于<head>tag,载于a.js。 这里有<条码>b.js,由下列单位创建:

document.getElementsByTagName( head )[0].appendChild(document.createElement( script ));  function show(){...} 

b.js;

now I want to invoke show() which in the b.js,but it goes error,because b.js hasn t loaded;

我想增加一些编码,以阻挡页数。

?


实际上, b. 在援引功能显示时,应装满;

but what about click event?in addition,I must put the show() in the page.

现在,我把另一支 j(基地.js)放在主角上,上述法典就是这样:

...
<head>
<script type="text/javascript" src="base.js"></script>
<script type="text/javascript" src="a.js"></script>
</head>
<body>
    <button id="test"></button>
    <script type="text/javascript">
        //invoke button click event from base.js and b.js
    </script>
</body>
...

for example,there are two click events bind to base.js and b.js(loaded ansync by a.js),when users click the button in the page,the event binded in base.js will be invoked immediately,but then...error...

我必须把援引人置于主角。

问题回答

您必须等到<代码>b.js装上。

页: 1 学历:

$("<script>").attr("src","b.js").appendTo("head").load(show);

《土著 Java》:

var ele = document.createElement( script );
ele.src = "b.js";
document.getElementsByTagName( head )[0].appendChild(ele);
ele.addEventListener("load",show,false);

不要阻挡页数,为什么你在<条码>上操作该代码。 窗口事件?

window.onload = function() {
    show();
};

你可以听一下上载活动,以确保他们在你执行该文字的任何内容之前装满。

//a simple script loader
function loadScript(url,callback){
    var s = document.createElement( script );                    //new script
    var document.getElementsByTagName( head )[0].appendChild(s); //append to head
    s.onload = function(){                                       //add onload
        callback();                                              //callback when done
    }
    s.src = url;                                                 //start download
}

//load b.js and run "show()" when b.js is loaded
loadScript( b.js ,function(){
    show();
});




相关问题
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.

热门标签