PHP messes up <script> in the .tpl header
I am writing some php code that creates pages from tpl files, which works just fine. However, I have decided to include some funky jquery stuff using the jqueryui engine and I can't get it to work. In the header.tpl, I have the following
<script src="...."></script>
<script>
$(function() {
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$("#dialog-message").dialog({ autoOpen: false })
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
$("#tac").click(function() {
$( "#dialog-me开发者_StackOverflowssage" ).dialog('open');
// prevent the default action, e.g., following a link
return false;
});
});
</script>
This code produces the desired effect when I test it in a plain html page. However, when the page is produced by the php code, it just doesn't. Besides, when I view source on this php-generated page, this is what I get in the header
<script>
$(function() )
$( "#dialog-message" ).dialog(
}
});
$("#tac").click(function() );
});
</script>
PHP seems to destroy most of the code and I can't understand why it happens. Any help would be greatly appreciated!
Since you haven't shown any PHP code or told us how the backend works, I have to guess. It really seems as if you are using Smarty or any other similar template engine. Had the same issue when I started using it.
Have a look at this documentation
So, do it this way:
{literal}
// your javascript code
{/literal}
try doing
<script type="text/javascript">...</script>.
And make sure your
<scripts />
arn't wrapped around any
<?php ?>
tags
精彩评论