質問

I'm trying to use a php code snippet for jQuery Cycle Slideshow, but the console gives me this error:

"Uncaught SyntaxError: Unexpected token < "

var startingSlide = <?php echo $_GET["thumb"] ?>;

$(slideshowContainer).cycle ({
    startingSlide: startingSlide
});

How can I use the PHP code correctly?

I'd appreciate you help.

役に立ちましたか?

解決

PHP doesn't parse files with a .js ending, but you could have the PHP parser parse javascript files, but that's a really bad idea, instead insert the PHP in the PHP file where it belongs, and get the data with javascript

<div id="some_element" data-startingslide="<?php echo $_GET["thumb"] ?>"></div>

then do

var startingSlide = $('#some_element').data('startingslide')

$(slideshowContainer).cycle ({
    startingSlide: startingSlide
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top