call jquery fom php script
<script type="text/javascript">
<!--//
// on DOM ready
$(document).ready(function (){
$("#current_rev").html("v"+$.jnotify.version);
$("a.example").bind("click", function (e){
// prevent default behavior
e.preventDefault();
var $ex = $($(this).attr("href")), code = $.trim($ex.text());
// execute the sample code
$.globalEval(code);
});
// style switcher
$("button.css_switcher").click(function (){
switchCSS(this.title);
});
});
//-->
</script>
Instead of using click events like <a href="#example-1" class="example">[Run]</a> and <a href="#example-2" class="example">[Run]</a>
How can I call events if a condition is true or false?
<?php
if (true){
<a href="#example-1" class="example">[Run]</a>}else{
<a 开发者_C百科href="#example-2" class="example">[Run]</a>}
?>
You mean "trigger" events? Your question is a bit confusing.
You can just add $("#example-1").trigger("click")
to the document.ready function.
So if a condition is true on the server side it will do something on the client side when the page gets sent to the user.
Make sure you attach the click event before you trigger it.
$(function () {
// all event binds and other code
<?php
if ( $trigger ) {
echo "$('#".$element_id."').trigger( 'click' )";
}
?>
}
Make $trigger
a true false and give all your links ids and pass the id as $element_id
精彩评论