About Easyui's Window and tab page do not perform JS description

Source: Internet
Author: User

There have been many people in the group response, in the tab loading interface, the interface of the JS will not be executed. Today godson here to explain why.

Both the Window,dailog and the tab quality eventually inherit the panel. The Panel has two ways of presenting the content. The first is the direct hard-coded write-out. The second is to load the external HTML fragment through the href attribute. The concept of an HTML fragment is designed here. This concept is a very important concept in the overall architecture of Easyui, because many people do not understand it, so it causes a lot of problems. Let me give an example to illustrate the HTML fragment.

We all know that the standard structure of HTML is:

1 <html>
2 <head>
3     <title>这是完整的html结构</title>
4     <script></script>
5 </head>
6 <body>
7 <div>内容</div>
8 </body>
9 </html>

Generally we write HTML code that should follow this structure. The so-called HTML fragment is the content part of the complete structure above.

1 <div>内容</div>

Although we will also create a file such as b.html to save the HTML fragment, but in this b.html we only need to write <body> inside the content does not need to write the standard structure of HTML.

Well, to understand the concept of HTML fragments, I'm going to use a lot of HTML fragments in the process of using a easyui.

In fact, in the use of Easyui you do not embed the IFRAME, in addition to the index interface will have a complete HTML structure, all the other interfaces are in the form of HTML fragments. For that tab, first define a tabs on the interface

01 <html>
02 <head>
03 <title>tab测试界面</title>
04 </head>
05 <body>
" < Code class= "keyword" >div class = "Easyui-tabs" fit = "true" plain = "true" style = "height:100px;width:300px;" >
"    ;    < div title = "Title1" style = "padding:10px;" href = "tabs_href_test.html" ></ div >
"    ;    < div title = "Title2" style = "padding:10px;" >content 2</ div >
09     <divtitle="Title3"style="padding:10px;">Content 3</div>
10 </div>
11 </body>
12 </html>

See the Title= "Title1" at the top of the clip. I've defined a tab where the HREF attribute is used to indicate that this is where you want to load an HTML fragment externally to display the contents of the tab. Here's what I've defined for tabs_href_test.html.

1 <scripttype="text/javascript"src="test.js"></script>
2 <script>alert("我是外部加载的html片段");</script>
3 <div><p>我是外部加载的html片段</p></div>

Content of Test.js:

1 alert("我是外部界面导入的js");

There must be a lot of people here to tell me, I wrote this, but my JS is not executed at all. In fact, I have seen a lot of people who want me to solve the problem of the class, sent me to see the code. If tabs_href_test.html were the external interface they introduced, it would be a complete structure like the following

01 <html>
02 <head>
03 <metahttp-equiv="Content-Type"content="text/html; charset=UTF-8">
04 <title>Tabs - jQuery EasyUI Demo</title>
05   <scripttype="text/javascript"src="test.js"></script>
06   <script>alert("我是外部加载的html片段");</script>
07 </head>
08 <body>
09   <div><p>我是外部加载的html片段</p></div>
10 </body>
11 </html>

They will all ask why JS is not executed. In fact, the problem is here. The tabs_href_test.html interface is actually the JQ request over the content via Ajax, in the append to the target area. The responsetext of the Ajax request method only grabs the contents of <body> inside the full HTML fragment. Just as they wrote their JS out of the body so that JS did not execute. This is true in the introduction of the interface does not appear

Finally, if you should use the Easyui to load the external interface components, such as: Panel,window,dailog,tabs. Make sure that the interface you introduce is an HTML fragment. HTML fragment correct wording again reminder do not appear

View Sourceprint?
1 <scripttype="text/javascript"src="test.js"></script>
2 <linkref="css"/>
3 <style>还可以写点样式</style>
4 <script>alert("我是外部加载的html片段");</script>
5 <div><p>我是外部加载的html片段</p></div>

About Easyui's Window and tab page do not perform JS description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.