 |
|
|  |
ÀÔ·Â Çʵ忡¼ ƯÁ¤´Ü¾î(¿¹:#err)°¡ Æ÷ÇԵǾúÀ» ¶§ ½Ç½Ã°£ °¨Áö ¹× °æ°íâ ¶ç¿ì±â |
|
|
 |
11ÀÏ Àü |
1, JavaScriptÀÇ input À̺¥Æ® ¸®½º³Ê¸¦ »ç¿ëÇÏ¿© »ç¿ëÀÚ°¡ ÀÔ·ÂÇÒ ¶§ #err ´Ü¾î°¡ Æ÷ÇԵǾú´ÂÁö ½Ç½Ã°£ üũÇÏ¿© °æ°íâÀ» ¶ç¿ìµµ·Ï ±¸ÇöÇÒ ¼ö ÀÖ½À´Ï´Ù.
<input type="text" name="link1" id="link1" value="<?=$link1?>" style="width:98%;" class="input" />
<script>
document.getElementById("link1").addEventListener("input", function() {
const inputValue = this.value;
if (inputValue.includes("#err")) {
alert("°æ°í: ÀԷ°ª¿¡ '#err'ÀÌ Æ÷ÇԵǾú½À´Ï´Ù.");
this.value = inputValue.replace("#err", ""); // ÀÚµ¿ Á¦°Å
}
});
</script>
¼³¸í
document.getElementById("link1") ¡æ input Çʵ带 °¡Á®¿È
.addEventListener("input", function() { ... })
»ç¿ëÀÚ°¡ ÀÔ·ÂÇÒ ¶§¸¶´Ù input °ª ½Ç½Ã°£ °¨Áö
if (inputValue.includes("#err")) { alert(...) }
#errÀÌ Æ÷ÇÔµÇ¸é °æ°íâ(alert) ¶ç¿ò
ÀԷ°ª¿¡¼ #errÀ» ÀÚµ¿À¸·Î Á¦°Å (this.value = inputValue.replace("#err", "");)
2, °æ°íâ(alert) ´ë½Å ÀÔ·Â Çʵ带 »¡°£»ö Å׵θ®·Î °Á¶ÇÏ°í, °æ°í ¸Þ½ÃÁö¸¦ Ç¥½ÃÇÒ ¼öµµ ÀÖ½À´Ï´Ù.
<input type="text" name="link1" id="link1" value="<?=$link1?>" style="width:98%;" class="input" />
<script>
document.getElementById("link1").addEventListener("input", function() {
// "#err"ÀÌ Æ÷ÇԵǾúÀ» °æ¿ì ÀÔ·Â ÇÊµå °Á¶
if (this.value.includes("#err")) {
this.style.border = "2px solid red"; // »¡°£»ö Å׵θ® Àû¿ë
}
// "#err" ÀÚµ¿ Á¦°Å
const newValue = this.value.replace(/#err/g, "");
if (this.value !== newValue) {
this.value = newValue;
// "#err"ÀÌ Á¦°ÅµÈ ÈÄ¿¡µµ Àá½Ã »¡°£ Å׵θ®¸¦ À¯Áö
setTimeout(() => {
this.style.border = ""; // ¿ø·¡ Å׵θ®·Î º¹±¸
}, 500); // 0.5ÃÊ ÈÄ ¿ø·¡ »óÅ·Î
}
});
</script>
¼³¸í
this.value.includes("#err")
ÀԷ°ª¿¡ #errÀÌ Æ÷ÇԵǾú´ÂÁö ½Ç½Ã°£À¸·Î È®ÀÎÇÕ´Ï´Ù.
this.style.border = "2px solid red";
ÀÔ·Â Çʵ带 »¡°£»ö Å׵θ®·Î °Á¶ÇÕ´Ï´Ù.
this.value = this.value.replace(/#err/g, "");
ÀԷ°ª¿¡¼ #errÀ» ÀÚµ¿À¸·Î Á¦°ÅÇÕ´Ï´Ù.
else ºí·Ï
Á¤»ó ÀÔ·ÂÀÏ °æ¿ì Å׵θ®¸¦ ¿ø·¡´ë·Î º¹±¸ÇÕ´Ï´Ù.
ÀÌÁ¦ ÀÔ·Â Çʵ忡 #errÀ» ÀÔ·ÂÇϸé ÀÚµ¿À¸·Î Á¦°ÅµÇ¸é¼ »ç¿ëÀÚ¿¡°Ô ½Ã°¢Àû °æ°í°¡ Á¦°øµË´Ï´Ù. |
|
̵̧ : 4 |
̵̧
¸ñ·Ï
|
|
|  |
|