ÐÂÈËjavascriptÎÊÌâÇóÖú£¬Çë¸÷λ´ó¸ç´ó½ãÃÇÀ´°ï棡
ÕâÊÇÎÒµÄÎı¾¿ò
<input type="text" size="60" name="password_answer" id="pwdanswer" value="$!password_answer" >
Ìá½»°´Å¥
<input class="standardButton" type="submit" name="submitType" oncvalue="Ok">
ÏÖÔÚÓиöHTMLÎÊÌ⣬ ¾ÍÊǵ±ÎÒÊäÈë(< > & etc)ÕâЩʱºò£¬Ò»Ìá½»£¬Ëü¾Í»á±ä³É < À¨ºÅ£¬½â¾ö¾ÍÊÇÓÃÕâ¸öÀ´(&lt; &gt; &amp; etc)Ìæ»»£¬Æäʵ¾ÍÊÇ&gt;µÈÓÚ>
ÎÒÕÒµ½ÁËÒ»¸öjavascriptµÄreplace()·½·¨£¬¾ÍÊÇÏë°ÑÊäÈë>Ìύʱºò£¬ÓÃ&gt;Ìæ»»£¬¾ÍÕâ4¸ö¡£
µ«ÊDz»ÖªµÀÈçºÎʹÓÃjavascriptµÄreplace()·½·¨£¬Çë¸÷λ´ó¸ç»áµÄ»°½Ì½ÌСµÜ¡£¸Ðл
ÔÚsubmit°´Å¥ÉÏÉèÖÃonClick="return methon();"
JScript code:
<script>
function methon(){
var dict = {"<",">"};
var words = {"<",">"};
var pwdanswer = document.getElementById("pwdanswer");
var pwdstr = pwdanswer.value;
for(var i = 0; i < dict.length; i++){
pwdstr = pwdstr.replaceAll(dict[i],words[i]);
}
pwdanswer.value=pwdstr;
return true;
}
<script>
Ïà¹ØÎÊ´ð£º
±ÈÈçÓÐÒ»¸ötextbox£¬Óû§ÊäÈëºóµãbutton°´Å¥Ê±£¬ÊµÏÖÓÃJavaScript¶ÔtextboxÊäÈëÐÅÏ¢µÄÑéÖ¤£¬±ÈÈçÑéÖ¤Óû§ÊäÈëµÄÊÇ·ñÊÇÊý×Ö¡£
Ï£Íû½«HTML´úÂëÒ»²¢Ð´³öÀ´¹þ£¬Ð»Ð»¡£
HTML code:
<!DOCTYPE html PUBLIC &quo ......
ÈçÓÐÒ»¸ötextbox£¬Óû§ÊäÈëºóµãbutton°´Å¥Ê±£¬ÊµÏÖÓÃJavaScript¶ÔtextboxÊäÈëÐÅÏ¢µÄÑéÖ¤£¬ÒªÇóÓÃJavaScriptÀ´ÊµÏÖ£¬±ÈÈçÑéÖ¤Óû§ÊäÈëµÄÊÇ·ñÊÇÊý×Ö¡£
Ï£Íû½«HTML´úÂëÒ»²¢Ð´³öÀ´¹þ£¬Ð»Ð»
HTML code:
<!DOC ......
ÎÊÌâÃèÊöÈçÏ£º
ÓÃC#¿ª·¢µÄActiveXǶÈëÍøÒ³ÖУ¬¸ÃActiveXÖÐÓÐÒ»¸ö°´Å¥button1.ÏÖÔÚҪʹµÃÓû§µ¥»÷ÁËbutton1ºóʵÏÖÒ³ÃæÌøתµÄ¹¦ÄÜ£¬¼´Óɵ±Ç°µÄ1.htmÌøתµ½2.htm¡£
Î ......
javascriptÖÐ2¼¶Ê¼þÖÐDOM°ÑËü·ÖÎļþÊ÷£¬ÄǸöÎļþÊ÷µÄ½á¹¹ÊÇÔõôÑùµÄ£¿2¼¶´«²¥Öи¸½ÚµãºÍ×Ó½ÚµãµÄ¹Øϵ£¬ÄܾٸöÀý×Ó˵Ã÷Ò»ÏÂÂð£¿ÊéÉÏдµÃºÜÂÒ£¬Àý×ÓҲû¾Ù¡£Ð»Ð»ÁË£¡
µÍÊÖÆ®¹ý¡£
˵ÆðÀ´ÊÇͦ¸´Ôӵģ¬² ......