테스트 사이트 - 개발 중인 베타 버전입니다

alert창을 SweetAlert2를 사용해서 바꾸기 채택완료

김마린2 3년 전 조회 18,834
스크립트 변수 선언 후

 

</p>

<p>// 출석 시간 체크

if (date("H:i:s") < $att_start_time || date("H:i:s") > $att_end_time) {

    alert("출석 시간이 아닙니다.");

    exit;

}</p>

<p>
기존 코드입니다 여기서 시스템 alert을 sweetalert 으로 바꾸고싶어

 

</p>

<p>// 출석 시간 체크

if (date("H:i:s") < $att_start_time || date("H:i:s") > $att_end_time) {</p>

<pre class="language-php">
<code class="language-php"><span class="token operator"><</span>script<span class="token operator">></span>
Swal<span class="token punctuation">.</span><span class="token function">fire</span><span class="token punctuation">(</span><span class="token punctuation">{</span> 
    text<span class="token punctuation">:</span> <span class="token double-quoted-string string">"출석 시간이 아닙니다."</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span>ok<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>window<span class="token punctuation">.</span>history<span class="token punctuation">.</span><span class="token function">back</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token operator"><</span><span class="token operator">/</span>script<span class="token operator">></span>
</code>}
</pre>

<p>

 

위와 같이 변경했는데 실제 실행 시 페이지 오류가 발생하네요 ㅠㅠ

어느부분이 문제인지 확인해주시면 감사하겠습니다
댓글을 작성하려면 로그인이 필요합니다.

답변 5개

채택된 답변
+20 포인트
Dessi
3년 전

cdn이 잘못된것 같은데요.

사용중이신건 1인것 같고

 

2는

<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

이걸로 바꿔보세요,

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

김마린2
3년 전
안녕하세요!

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
-> <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

변경했는데도 증상은 동일합니다 ㅠ
D
Dessi
3년 전
php 소스 뺴고 스립트만 해보세요.(페이지 새로고침 하면 경고 떠야함)

만약 그래도 오류 뜬다면 php 변수 오류일겁니다.

댓글을 작성하려면 로그인이 필요합니다.

cdn 말고 로컬에서 js파일과 css파일을 불러오시는게 어떨지...

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

들레아빠

<link href="//cdn.jsdelivr.net/npm/@sweetalert2/theme-dark@4/dark.css" rel="stylesheet">
<script src="//cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.js"></script>

이걸 먼저 실행하고 해 보세요.

저는 sweetalert.js이거 하나만 사용합니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

3년 전
전체 흐름은 몰겠지만
Swal.fire({ 
    text: "출석 시간이 아닙니다."
}).then((ok) => {window.history.back()});

이부분을 바꿔보세용.

1안.

</p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>swal.fire({ </code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>    text: "출석 시간이 아닙니다." </code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>}).then((ok) => {</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>    if (ok) {</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>        window.history.back()</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>    }</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>});</code></span></span></p>

<p>

2안.(2버전기준)

</span></font></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>swal.fire({ </code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>    text: "출석 시간이 아닙니다." </code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>}).then((ok) => {</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>    if (ok.isConfirmed) {</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>        window.history.back();</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>    }</code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>});</code></span></span></p>

<p>

3안 (간단버젼)

</p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>swal.fire({ </code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>    text: "출석 시간이 아닙니다." </code></span></span></p>

<p><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>}).then(() => {</code></span></span><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code> window.history.back() </code></span></span><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>}</code></span></span><span style="font-size:10pt;"><span style="font-family:맑은 고딕;"><code>);</code></span></span></p>

<p><font face="monospace"><span style="font-size: 13.3333px;">

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

하틴
3년 전

</p>

<pre>
<code><?
// 출석 시간 체크
if (date("H:i:s") < $att_start_time || date("H:i:s") > $att_end_time) {
?>
<script>
Swal.fire({ 
    text: "출석 시간이 아닙니다."
}).then((ok) => {window.history.back()});
</script>
<?}?>
</code></pre>

<p>

php와 js를 구분해주셔야할 것 같습니다.

<??> 표기나 echo 로 감싸주시면 될 것 같습니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

김마린2
3년 전
답변 감사드립니다 우선 위소스와 동일하게 적용시에도
페이지가 작동하지 않습니다 라고 나오네요 ㅠ

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인