我知道在Stack Overflow上已经问过很多类似的问题,但是我在html/php中存在三重嵌套引号的问题.我已经看过许多问题,但是没有找到适合我的解决方案.这是我想要做的(在php文件中找到):
I know that similar questions have been asked on Stack Overflow many times, but I am having problems with triple nested quotes in html/php. I have looked at numerous questions, but none of the solutions that I have found are working for me. Here is what I am trying to do (this is found in a php file):
echo"<div id = 'feed-element'> <button class='username-button' type='button'>@".$currentUsername."</button> <button class='hashtag-one-button' type='button'>".$hashtag_one."</button> <button class='hashtag-two-button' type='button'>".$hashtag_two."</button> <button class='play-button' id='play-button".$i."' type='button' onclick='changeImage(this.id,\'".$track_url."\')'></button> <button class='email-button' type='button'>Contact: ".$email."</button> </div>";导致我出现问题的特定行是倒数第三行:
The specific line that is causing me problems is the third to last line:
<button class='play-button' id='play-button".$i."' type='button' onclick='changeImage(this.id,\'".$track_url."\')'></button>无论如何,当我运行这段代码时,我得到了一个Uncaught语法:无效或意外的令牌错误.我在做什么错了?
Anyways, when I run this code I get an Uncaught Syntax: invalid or unexpected token error. What am I doing wrong?
推荐答案对于引起错误的代码,您需要转义双引号,而不是单引号:
For your error-causing code, you need to escape double quotes, not single:
<button class='play-button' id='play-button".$i."' type='button' onclick='changeImage(this.id,\"".$track_url."\")'></button>因为使用双引号,所以不需要串联.只需插入变量就可以了!
Because you are using double quotes, you don't need to concatenate. Just insert the variable and away you go!
echo"<div id='feed-element'> <button class='username-button' type='button'>@$currentUsername</button> <button class='hashtag-one-button' type='button'>$hashtag_one</button> <button class='hashtag-two-button' type='button'>$hashtag_two</button> <button class='play-button' id='play-button$i' type='button' onclick='changeImage(this.id,\' $track_url\ ')'></button> <button class='email-button' type='button'>Contact: $email</button> </div>";更多推荐
php/html
发布评论