echo 내에 따옴표 처리에 관하여
본문
echo "<input class='button2' type='button' value='확인' onclick='document.location.href='./p.php'' />";
기초가 없다보니 이런데서 헤매네요.
위 코드에서 onclick='document.location.href='./p.php'' 이부분 따옴표를 어떻게 처리해야하는지 궁굼합니다.
!-->답변 3
echo "<input class='button2' type='button' value='확인' onclick=\"document.location.href='./p.php' \" />";
이렇게 해보세요
onclick=location.href='./p.php'
따옴표 없이 이렇게만 써도 됩니다.
+ echo
- https://www.php.net/manual/en/function.echo
- https://www.php.net/manual/en/language.types.string.php
- https://www.php.net/manual/en/language.types.array.php
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"로 감싼 안쪽에 " 표시는 \" ... echo "this is \"test\" string - 'ok'";
'로 감싼 안쪽에 ' 표시는 \' ... echo 'this is \'test\' string - "ok"';
echo "<input class=\"button2\" type=\"button\" value=\"확인\" onclick=\"document.location.href='./p.php'\" />";
echo '<input class="button2" type="button" value="확인" onclick="document.location.href=\'./p.php\'" />';
답변을 작성하시기 전에 로그인 해주세요.