Script"
m ((via JWB)) |
|||
Line 52: | Line 52: | ||
=Defer the Evaluation= | =Defer the Evaluation= | ||
− | By default, the specified JavaScript code will be evaluated as soon as the page is loaded | + | By default, the specified JavaScript code will be evaluated as soon as the page is loaded. By specifying <code>defer="true"</code>, the JavaScript code won't be evaluated until all ZK widgets are created and bound to the DOM tree. |
− | < | + | <syntaxhighlight lang="xml"> |
<textbox id="inp"/> | <textbox id="inp"/> | ||
<script defer="true"> | <script defer="true"> | ||
this.$f("inp").setValue("initialized"); | this.$f("inp").setValue("initialized"); | ||
</script> | </script> | ||
− | </ | + | </syntaxhighlight> |
The defer attribute can be used with a JavaScript file as shown below. Then, the JavaScript file will be loaded after all widgets are created and bound to the DOM tree. | The defer attribute can be used with a JavaScript file as shown below. Then, the JavaScript file will be loaded after all widgets are created and bound to the DOM tree. | ||
Line 66: | Line 66: | ||
<script src="/js/foo.js" defer="true"/> | <script src="/js/foo.js" defer="true"/> | ||
</syntax> | </syntax> | ||
+ | |||
+ | This is required if the script to load intends to manipulate a ZK widget's DOM elements | ||
=Supported Events= | =Supported Events= |
Revision as of 06:42, 21 December 2023
Script
Employment/Purpose
The script component is used to specify the script codes running at the browser. Notice that, unlike zscript, the script codes are running at the browser. They are usually written in JavaScript which is supported by the most of browsers. The simplest format is as follows.
Example
<syntax lang="xml" >
<zk>
<window id="win"> <button label="change color" onClick='Clients.evalJavaScript("myfunc()")' /> </window> <script type="text/javascript"> function myfunc() { jq("$win").css("backgroundColor", "blue"); }
</script>
</zk> </syntax>
Alternatives
Instead of using the script component, you could use the script directive instead. It does not support defer, but it is more efficient since no component is created.
<?script src="~./js/zk.debug.wpd"?>
<?script content="jq.IE6_ALPHAFIX='.png';"?>
where the first statement loads the debug utility and the second generates JavaScript code snippet directly.
Another alternative is HTML SCRIPT. For example, we could define global variables and functions as follows
<n:script xmlns:n="native"><!-- use the native namespace -->
var a_global_variable;
function a_global_function () {
alert("native script");
}
alert("you can not access this as widget but evaluated immediately");
</n:script>
Defer the Evaluation
By default, the specified JavaScript code will be evaluated as soon as the page is loaded. By specifying defer="true"
, the JavaScript code won't be evaluated until all ZK widgets are created and bound to the DOM tree.
<textbox id="inp"/>
<script defer="true">
this.$f("inp").setValue("initialized");
</script>
The defer attribute can be used with a JavaScript file as shown below. Then, the JavaScript file will be loaded after all widgets are created and bound to the DOM tree.
<syntax lang="xml"> <script src="/js/foo.js" defer="true"/> </syntax>
This is required if the script to load intends to manipulate a ZK widget's DOM elements
Supported Events
None | None |
- Inherited Supported Events: AbstractComponent
Supported Children
*NONE
Use Cases
Version | Description | Example Location |
---|---|---|
5.0 | Overview and Tutorial | Client Side Programming |
Version History
Version | Date | Content |
---|---|---|