duanhui7329 2016-02-11 03:48
浏览 48
已采纳

如何在php echo中转义第二层html引号?

I cannot find a way to escape second tier html quotes in a php echo:

PHP 
echo "<div id='myDiv'></div>
<select onchange='myfunction(this,"#myDiv")'>
options and such 
</select>
";

It seems the escape has to apply to not only php but also to html for them to work. I even tried to save the second argument to myfunction as a php variable and passing it in the echo but then jquery didn't accept this. .. or maybe I just did it wrong.

  • 写回答

2条回答 默认 最新

  • dtslobe4694 2016-02-11 06:57
    关注

    Try using like this:

       echo '<div id="myDiv"></div>
              <select onchange="myfunction(this,\'#myDiv\')">
                  options and such 
              </select>';        
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?