webǰ¶Ë¿ª·¢Åàѵ֮³¬Ç¿µÄJS×ܽᣨһ£©
¸üÐÂʱ¼ä:2016Äê10ÔÂ12ÈÕ14ʱ45·Ö À´Ô´:ÀÖÓã²¥¿Íǰ¶ËÓëÒÆ¶¯¿ª·¢Ñ§Ôº ä¯ÀÀ´ÎÊý:
1. Çå³ýÊÓ´°»òframeÖеÄÄÚÈÝ
document.clear();
document.close(); document.open(); document.write(“”);
2. ÔÚ²»Í¬ÎļþÖ®¼ä´©Ëó
document.back(); document.forward();
history.go(-1); history.go(1);
3. ÊäÈë¿ò
var the_url = prompt("What's the URL?","");
if£¨the_url==””||the_url==null£©{
the_url=”www.google.com”;
}
×¢£ºÀûÓÃthe_url==null¿ÉÒÔÅжÏѡȡµÄÊÇÈ¡Ïû°´Å¥
4. È·¶¨¿ò
<script language="javascript">
function delete_confirm(qyyb_no,inspect_time,company_name){
<!—µã»÷È·¶¨°´Å¥-- >
if(confirm("È·¶¨ÒªÉ¾³ý¸ÃÆóÒµÔ±¨Âð£¿"))
{
location.href='<%=request.getContextPath()%>/webcontroller?functionId=2015&inspect_time='+inspect_time+'&company_name='+company_name+'&qyyb_no='+qyyb_no;
alert('ÆóÒµÔ±¨É¾³ý³É¹¦£¡');
window.close();
}
<!—µã»÷È¡Ïû°´Å¥-- >
else{
}
}
</script>
5. ÄÚÖñäÁ¿top£¬¸Ã±äÁ¿ÓÀÔ¶Ö¸·Ö¸î´°¿Ú×î¸ß²ã´ÎµÄä¯ÀÀÆ÷´°¿Ú¡£Èç¹ûÄã¼Æ»®´Ó·Ö¸î´°¿ÚµÄ×î¸ß²ã´Î¿ªÊ¼Ö´ÐÐÃüÁÄã¾Í¿ÉÒÔÓÃtop±äÁ¿¡£
<a href="#" onClick="top.target_frame.document.writeln('Monkey do!<br>');">Monkey see</a>
Ö´ÐиÃÓï¾äʱ£¬JavaScript´Ó´°¿ÚµÈ¼¶µÄ×î¸ß²ã¿ªÊ¼£¬¸Ã²ãÖаüº¬×ŷָ¿ÚµÄ´°¿ò£¬´ÓÖз¢ÏÖÃû½Ðtarget_frameµÄ·Ö¸î´°¿Ú£¬ÓÉÓڸ÷ָ¿ÚÊÇÒ²Ò»¸ö´°¿Ú£¬ËùËü¾ßÓд°¿ÚµÄÎļþ£¨document£©ÊôÐÔ¡£JavaScriptÕÒµ½ÆädocumentÊôÐÔ£¬²¢µ÷ÓÃwriteln()·½·¨¡£ÆäÖ´Ðнá¹ûÊÇÔÚÎļþÖÐд³ö"Monkey do!" ¡£writeln()ÊÇÎļþ£¨document£©¶ÔÏóµÄ·½·¨£¬ËùÒÔÎÒÃDZØÐëдdocument.writeln()
6. ´°¿ÚÓÐÒ»¸öÊôÐÔ½Ð×ödocument£¬ËüÓÃÓÚÒýÓõ½´°¿ÚÖÐʵ¼ÊµÄHTMLÎļþ¡£¸Ãdocument
ÊôÐÔ±¾Éí¾ÍÊÇÒ»¸ö¶ÔÏó¡£ÔÚ̸µ½Í¼Ïóµô»»£¨image swap£©µÄʱºò£¬ÎÒÃǼûµ½¹ýÕâÑùµÄÀý×Ó¡£Äã¿ÉÒÔÓÃÏÂÁÐÓï¾ä×÷ͼÏóµô»»:
<a href="#">½»»»</a>
ÉÏÊöÓï¾äµÄÒâ˼ÊÇ˵£ºÕÒµ½windowµÄdocumentÊôÐÔ£¬ÕÒµ½the_imageµÄsrcÊôÐÔ²¢½«ÆäÉèÖÃΪͼÏóbutton_d.gif¡£ÕâÑùдÊÇÒòΪ´°¿Ú£¨windows£©ÊǶÔÏ󣬴°¿ÚÄÚµÄÎļþ£¨documents£©ÊǶÔÏ󣬶øÎļþ£¨document£©ÄÚµÄͼÏó£¨images£©Ò³ÊǶÔÏó¡£
¿´ÆðÀ´ËƺõºÜ¸´ÔÓ£¬µ«ËüµÄ½á¹¹ºÜÇå³þ¡£JavaScriptµÄÎļþ¶ÔÏóÄ£¿é£¨Document Object Model£©ÃèÊöÁ˶ÔÏóÖ®¼äµÄµÈ¼¶¹ØÏµ¡£
7. WindowsÌØÐÔ£º window.open()ÖеĵÚÈý¸ö²ÎÊýÊÇÄãÏëÒªÄãµÄ´°¿Ú±íÏÖµÄÒ»×éÌØÐÔ¡£Èç¹ûÄã²»Íêȫȷ¶¨ÄãµÄ²ÎÊý£¬ÔòÒÔÓû§ä¯ÀÀÆ÷µÄÈ±Ê¡ÖµÌæ´ú¡£
È»¶ø£¬Èç¹ûÄãÖ¸¶¨ÁËÒ»Ð©ÌØÐÔ²ÎÊý£¬Ôò´°¿Ú½«ÒÔ²ÎÊýÉ趨ֵ¹æ¶¨µÄ³öÏÖ¡£ÌØÐÔ²ÎÊýÊÇÒÔÒ»×鶺ºÅ·Ö¸ôµÄÐòÁгöÏֵġ£
ÀýÈ磬Èç¹ûÄãÊÇÕâôдµÄ£º
window.open("some_url","window_name","location,menubar");
Ä㽫µÃµ½Ò»¸ö¹æ¶¨ÁËURL£¬´°¿ÚÃû¼°²Ëµ¥Ìõ£¨Îļþ£¬±à¼ÌõµÈµÈ£©µÄ´°¿Ú¡£×¢Òâ±ðÔÚ×Ö·û´®ÖмÓÈëÈκοոñ£¬Õ⽫ʹµÃÓÐЩä¯ÀÀÆ÷³ö´í¡£
¿´Ò»ÏÂÁíÒ»¸öÀý×Ó£º
window.open("some_url","window_name","location,height=100,width=100");
Õ⽫´ò¿ªÒ»¸ö¸ß¿í¸÷Ϊ100ÏñËØµÄ´°¿Ú¡£ÔÙ´ÎÇë×¢Òâ±ðÔÚ×Ö·û´®Öмӿոñ¡£
ÕâÀïÊÇÒ»×é¿ÉÒÔÔÚ×Ö·û´®ÖÐÒýÓõÄÌØÐÔ²ÎÊý£º
menubar £¨²Ëµ¥Ìõ£©
ÕâÊǸöÔÚ´ó¶àÊýÈí¼þÓ¦ÓÃÖж¼ÒýÓõĺ¯ÊýÐС£Ò»°ã°üÀ¨ÓÐÎļþ£¬±à¼¼°ÆäËûһЩÌõÄ¿¡£
status£¨×´Ì¬Ìõ£©
ÕâÊÇλÓÚÄãµÄ´°¿Úϲ¿µÄÐÅÏ¢Ìõ¡£µ±ÄãµÄÊó±êÒÆµ½Ò»¸öÁ´½ÓÉÏʱ£¬Á´½ÓµÄURL¾ÍÔÚÕâ¸ö״̬ÌõÉϳöÏÖ¡£Äã¿ÉÒÔ½«×´Ì¬ÌõÉÏÏÔʾµÄÄÚÈݰᵽһ¸ö¹ö¶¯µÄmarquee ÖÐÈ¥¡£ÎÒ²»´òËãΪÄã×öÕâ¸öʾÀý£¬Èç¹ûÄãÏëÖªµÀÔõÑù×ö£¬×Ô¼ºÉè·¨½â¾ö£¡
scrollbars £¨¹ö¶¯Ìõ£©
µ±ÐèҪʱÔÊÐí¹ö¶¯Ìõ³öÏÖ¡£
resizable £¨Öص÷£©
µ±Öص÷²ÎÊý±»Áгö£¬´°¿Ú½«¿É±»Öص÷¡£×¢ÒâËüµÄÆ´·¨£¬ÎҾ;³£¸ã´í¡£
width £¨¿í¶È£©
ÒÔÏñËØµã±í´ïµÄ´°¿Ú¿í¡£
height£¨¸ß¶È£©
ÒÔÏñËØµã±í´ïµÄ´°¿Ú¸ß¡£
toolbar £¨¹¤¾ßÌõ£©
Home button, among others.
ä¯ÀÀÆ÷¹¤¾ßÌõ£¬°üÀ¨ºóÍË£¬Ç°½øÅ¥£¬Í£Ö¹Å¥£¬ÒÔ¼°HOMEÅ¥µÈµÈ¡£
location £¨¶¨Î»Çø£©
Äã¿ÉÒÔ¼üÈëURL µÄä¯ÀÀÆ÷Îı¾Çø¡£
directories £¨Ö¸Ê¾Çø£©
ÈçNetscapeä¯ÀÀÆ÷ÖÐËùÔÚµÄ"What's new," "What's cool,"µÈµÈ¡£
8¡¢showModalDialogºÍshowModelessDialog
JavascriptÓÐÐí¶àÄÚ½¨µÄ·½·¨À´²úÉú¶Ô»°¿ò£¬È磺window.alert(), window.confirm(),window.prompt().µÈ¡£È»¶øIEÌṩ¸ü¶àµÄ·½·¨Ö§³Ö¶Ô»°¿ò¡£È磺
¡¡¡¡showModalDialog() (IE 4+ Ö§³Ö)
¡¡¡¡showModelessDialog() (IE 5+ Ö§³Ö)
window.showModalDialog()·½·¨ÓÃÀ´´´½¨Ò»¸öÏÔʾHTMLÄÚÈݵÄģ̬¶Ô»°¿ò£¬ÓÉÓÚÊǶԻ°¿ò£¬Òò´ËËü²¢Ã»ÓÐÒ»°ãÓÃwindow.open()´ò¿ªµÄ´°¿ÚµÄËùÓÐÊôÐÔ¡£
window.showModelessDialog()·½·¨ÓÃÀ´´´½¨Ò»¸öÏÔʾHTMLÄÚÈݵķÇģ̬¶Ô»°¿ò¡£
µ±ÎÒÃÇÓÃshowModelessDialog()´ò¿ª´°¿Úʱ£¬²»±ØÓÃwindow.close()È¥¹Ø±ÕËü£¬µ±ÒÔ·Çģ̬·½Ê½£ÛIE5£Ý´ò¿ªÊ±£¬´ò¿ª¶Ô»°¿òµÄ´°¿ÚÈÔ¿ÉÒÔ½øÐÐÆäËûµÄ²Ù×÷£¬¼´¶Ô»°¿ò²»×ÜÊÇ×îÉÏÃæµÄ½¹µã£¬µ±´ò¿ªËüµÄ´°¿Ú£Õ£Ò£Ì¸Ä±äʱ£¬Ëü×Ô¶¯¹Ø±Õ¡£¶øÄ£Ì¬£Û£É£Å£´£Ý·½Ê½µÄ¶Ô»°¿òʼÖÕÓн¹µã£¨½¹µã²»¿ÉÒÆ×ߣ¬Ö±µ½Ëü¹Ø±Õ£©¡£Ä£Ì¬¶Ô»°¿òºÍ´ò¿ªËüµÄ´°¿ÚÏàÁªÏµ£¬Òò´ËÎÒÃÇ´ò¿ªÁíÍâµÄ´°¿Úʱ£¬ËûÃǵÄÁ´½Ó¹ØÏµÒÀÈ»±£´æ£¬²¢ÇÒÒþ²ØÔڻ´°¿ÚµÄÏÂÃæ¡£
ʹÓ÷½·¨ÈçÏ£º
vReturnValue = window.showModalDialog(sURL [, vArguments][, sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments][, sFeatures])
²ÎÊý˵Ã÷£º
sURL
±ØÑ¡²ÎÊý£¬ÀàÐÍ£º×Ö·û´®¡£ÓÃÀ´Ö¸¶¨¶Ô»°¿òÒªÏÔʾµÄÎĵµµÄURL¡£
vArguments
¿ÉÑ¡²ÎÊý£¬ÀàÐÍ£º±äÌå¡£ÓÃÀ´Ïò¶Ô»°¿ò´«µÝ²ÎÊý¡£´«µÝµÄ²ÎÊýÀàÐͲ»ÏÞ£¬°üÀ¨Êý×éµÈ¡£¶Ô»°¿òͨ¹ýwindow.dialogArgumentsÀ´È¡µÃ´«µÝ½øÀ´µÄ²ÎÊý¡£
sFeatures
¿ÉÑ¡²ÎÊý£¬ÀàÐÍ£º×Ö·û´®¡£ÓÃÀ´ÃèÊö¶Ô»°¿òµÄÍâ¹ÛµÈÐÅÏ¢£¬¿ÉÒÔʹÓÃÒÔϵÄÒ»¸ö»ò¼¸¸ö£¬Ó÷ֺœ;”¸ô¿ª¡£
dialogHeight ¶Ô»°¿ò¸ß¶È£¬²»Ð¡ÓÚ£±£°£°px£¬£É£Å£´ÖÐdialogHeight ºÍ dialogWidth ĬÈϵĵ¥Î»ÊÇem£¬¶ø£É£Å£µÖÐÊÇpx£¬Îª·½±ãÆä¼û£¬ÔÚ¶¨Òåmodal·½Ê½µÄ¶Ô»°¿òʱ£¬ÓÃpx×öµ¥Î»¡£
¡¡¡¡dialogWidth: ¶Ô»°¿ò¿í¶È¡£
¡¡¡¡dialogLeft: ¾àÀë×ÀÃæ×óµÄ¾àÀë¡£
¡¡¡¡dialogTop: Àë×ÀÃæÉϵľàÀë¡£
¡¡¡¡center: {yes | no | 1 | 0 }£º´°¿ÚÊÇ·ñ¾ÓÖУ¬Ä¬ÈÏyes£¬µ«ÈÔ¿ÉÒÔÖ¸¶¨¸ß¶ÈºÍ¿í¶È¡£
¡¡¡¡help: {yes | no | 1 | 0 }£ºÊÇ·ñÏÔʾ°ïÖú°´Å¥£¬Ä¬ÈÏyes¡£
¡¡¡¡resizable: {yes | no | 1 | 0 } £Û£É£Å£µ£«£Ý£ºÊÇ·ñ¿É±»¸Ä±ä´óС¡£Ä¬ÈÏno¡£
¡¡¡¡status: {yes | no | 1 | 0 } £ÛIE5+£Ý£ºÊÇ·ñÏÔʾ״̬À¸¡£Ä¬ÈÏΪyes[ Modeless]»òno[Modal]¡£
scroll:{ yes | no | 1 | 0 | on | off }£ºÖ¸Ã÷¶Ô»°¿òÊÇ·ñÏÔʾ¹ö¶¯Ìõ¡£Ä¬ÈÏΪyes¡£
»¹Óм¸¸öÊôÐÔÊÇÓÃÔÚHTAÖеģ¬ÔÚÒ»°ãµÄÍøÒ³ÖÐÒ»°ã²»Ê¹Óá£
dialogHide:{ yes | no | 1 | 0 | on | off }£ºÔÚ´òÓ¡»òÕß´òÓ¡Ô¤ÀÀʱ¶Ô»°¿òÊÇ·ñÒþ²Ø¡£Ä¬ÈÏΪno¡£
edge:{ sunken | raised }£ºÖ¸Ã÷¶Ô»°¿òµÄ±ß¿òÑùʽ¡£Ä¬ÈÏΪraised¡£
unadorned:{ yes | no | 1 | 0 | on | off }£ºÄ¬ÈÏΪno¡£
´«Èë²ÎÊý£º
ÒªÏë¶Ô»°¿ò´«µÝ²ÎÊý£¬ÊÇͨ¹ývArgumentsÀ´½øÐд«µÝµÄ¡£ÀàÐͲ»ÏÞÖÆ£¬¶ÔÓÚ×Ö·û´®ÀàÐÍ£¬×î´óΪ4096¸ö×Ö·û¡£Ò²¿ÉÒÔ´«µÝ¶ÔÏó£¬ÀýÈ磺
test1.htm
====================
<script>
var mxh1 = new Array("mxh","net_lover","ÃÏ×ÓEÕÂ")
var mxh2 = window.open("about:blank","window_mxh")
// Ïò¶Ô»°¿ò´«µÝÊý×é
window.showModalDialog("test2.htm",mxh1)
// Ïò¶Ô»°¿ò´«µÝwindow¶ÔÏó
window.showModalDialog("test3.htm",mxh2)
</script>
test2.htm
====================
<script>
var a = window.dialogArguments
alert("Äú´«µÝµÄ²ÎÊýΪ£º" + a)
</script>
test3.htm
====================
<script>
var a = window.dialogArguments
alert("Äú´«µÝµÄ²ÎÊýΪwindow¶ÔÏó£¬Ãû³Æ£º" + a.name)
</script>
¿ÉÒÔͨ¹ýwindow.returnValueÏò´ò¿ª¶Ô»°¿òµÄ´°¿Ú·µ»ØÐÅÏ¢£¬µ±È»Ò²¿ÉÒÔÊǶÔÏó¡£ÀýÈ磺
test4.htm
===================
<script>
var a = window.showModalDialog("test5.htm")
for(i=0;i<a.length;i++) alert(a)
</script>
test5.htm
===================
<script>
function sendTo()
{
var a=new Array("a","b")
window.returnValue = a
window.close()
}
</script>
<body>
<form>
<input value="·µ»Ø" type=button>
</form>
³£¼ûÎÊÌ⣺
1£¬ÈçºÎÔÚģ̬¶Ô»°¿òÖнøÐÐÌá½»¶ø²»Ð¿ª´°¿Ú£¿
Èç¹ûÄã µÄä¯ÀÀÆ÷ÊÇIE5.5+,¿ÉÒÔÔÚ¶Ô»°¿òÖÐʹÓôønameÊôÐÔµÄiframe£¬Ìύʱ¿ÉÒÔÖÆ¶¨targetΪ¸ÃiframeµÄname¡£¶ÔÓÚIE4+£¬Äã¿ÉÒÔÓø߶ÈΪ0µÄframeÀ´×÷£ºÀý×Ó£¬
test6.htm
===================
<script>
window.showModalDialog("test7.htm")
</script>
test7.htm
===================
if(window.location.search) alert(window.location.search)
<frameset rows="0,*">
<frame src="about:blank">
<frame src="test8.htm">
</frameset>
test8.htm
===================
<form target="_self" method="get">
<input name=txt value="test">
<input type=submit>
</form>
<script>
if(window.location.search) alert(window.location.search)
</script>
2,¿ÉÒÔͨ¹ýhttp://servername/virtualdirname/test.htm?name=mxh·½Ê½Ö±½ÓÏò¶Ô»°¿ò´«µÝ²ÎÊýÂð£¿
´ð°¸ÊDz»ÄÜ¡£µ«ÔÚframeÀïÊÇ¿ÉÒԵġ£
showModalDialogºÍshowModelessDialogµÄÒìͬ
ͬ£ºÁ½Õßµ¯³öµÄ´°Ìå²»ÄÜË¢ÐÂ
Ò죺ǰÕßÊÇģ̬´°¿Ú£¬Ê¼ÖÕ»ñµÃ½¹µã£»ºóÕßÊÇ·Çģ̬´°¿Ú£¬Ö»²»¹ýµ¯³öÒ»¸öÒ³Ãæ£¬»¹¿ÉÒÔ²Ù×÷¸¸´°¿Ú¡£
¹Ø±ÕshowModalDialogºÍshowModelessDialogµ¯³öµÄ´°¿Ú
<INPUT type="button" value="ButtonClick">
ÔõÑù²ÅÈÃÔÚshowModalDialogºÍshowModelessDialogµÄµ¯³öд°¿ÚÀï²Ù×÷button,²»µ¯³öд°¿Ú£¿
ÔÚ<head>ºÍ</head>Ö®¼ä¼Ó<base target="_self">
showModalDialogµÄ·µ»ØÖµ
²ÎÕÕÀý×Ó£º
t1.html:
<script language="javascript">
function showpage()
{
alert(showModalDialog("t2.html"));
}
</script>
<input type="button" value="getval">
t2.html
<HTML>
<HEAD>
<Script language="javascript">
<
function SetVal()
{
returnValue="abc";
close();
}
//-->
</Script>
</HEAD>
<BODY>
<input type="button" value="Btn1">
</BODY>
</HTML>
window.showModalDialog ("dic_functionlist.jsp?dicid="+id,window,'dialogheight:300pt; dialogwidth:340pt; dialogtop:120pt; dialogleft:240pt;scrollbars:no;resizable:no;location:no;status:no');
9.ÄÚÖñäÁ¿ÊÇparent£¬Ö¸µÄÊǰüº¬µ±Ç°·Ö¸î´°¿ÚµÄĸ´°¿Ú¡£Èç¹ûÔÚÒ»¸ö´°¿ÚÄÚÓзָ¿Ú£¬¶øÔÚÆäÖеÄÒ»¸ö·Ö¸î´°¿ÚÖÐÓÖ°üº¬×ŷָ¿Ú£¬ÔòµÚ2²ãµÄ·Ö¸î´°¿Ú¿ÉÒÔÓÃparent±äÁ¿ÒýÓðüº¬ËüµÄĸ·Ö¸î´°¿Ú¡£
10. ¸´Ñ¡¿òÊÇ·ñÑ¡ÖÐ
var is_checked =
window.document.the_form.the_checkbox.checked;
if (is_checked == true)
{
alert("Yup, it's checked!");
} else {
alert("Nope, it's not checked.");
}
11. ¸´Ñ¡¿òʵÀý1
<form name="form_1">
<input type="checkbox" name="check_1">Checkbox 1
</form>
<a href="#"
onClick=
"window.document.form_1.check_1.checked=true;
return false;">
Click to check Checkbox 1</a>
<a href="#"box-sizing: border-box; color: rgb(51, 51, 51); font-family: arial, verdana, 'Microsoft YaHei', Tahoma, Simsun, sans-serif; line-height: 25.2px;">return false;">
Click to uncheck Checkbox 1</a>
<a href="#"
onClick="alert(window.document.form_1.check_1.checked);
return false;">
Click to see the value of Checkbox 1</a>
×¢ÒâÎÒÔÚÁ´½ÓÖÐʼÖÕ¼ÓÈëÁËreturn false£¬ÒÔ·ÀÖ¹ä¯ÀÀÆ÷Ë¢ÐÂÒ³ÃæÓֻص½ÔÀ´µÄÄÚÈÝ¡£
¸´Ñ¡¿òµÄʼþ´¦ÀíÆ÷ÊÇonClick¡£µ±Ä³È˵ã»÷¸´Ñ¡¿òʱ£¬onClickʼþ´¦ÀíÆ÷¼´·¢»Ó×÷Óá£
12. ¸´Ñ¡¿òʵÀý2
<form name="form_2">
<input type="checkbox" name ="check_1"
onClick="switchLight();">The Light Switch
</form>
µ±Ä³È˵ã»÷¸´Ñ¡¿òʱ£¬onClick´¦ÀíÆ÷±»¼¤»î²¢Ö´Ðк¯ÊýswitchLight()£¬ÒÔÏÂΪº¯ÊýswitchLight() µÄ±àÂ루ËüÖÃÓÚÍøÒ³Êײ¿ÖУ©:
function switchLight()
{
var the_box = window.document.form_2.check_1;
var the_switch = "";
if (the_box.checked == false) {
alert("Hey! Turn that back on!");
document.bgColor='black';
} else {
alert("Thanks!");
document.bgColor='white';
}
}
13. µ¥Ñ¡¿òʵÀý
±íµ¥±àÂëÈçÏÂ
<form name="form_1">
<input type="radio" name ="radio">Light off
<input type="radio" name ="radio" checked>Light on
</form>
µ±µÚÒ»¸öµ¥Ñ¡¿ò±»Ñ¡ÖÐʱ£¬º¯ÊýoffButton() ±»µ÷Ó᣺¯ÊýÈçÏ£º
function offButton()
{
var the_box = window.document.form_1.radio[0];
if (the_box.checked == true)
{
window.document.form_1.radio[1].checked = false;
document.bgColor='black';
alert("Hey! Turn that back on!");
}
}
Õâ¸öÀý×ÓºÜÏóÇ°ÃæµÄ¸´Ñ¡¿òÀý×Ó£¬Ö÷ÒªµÄÇø±ðÔÚÓÚ¸ÃÐУº
window.document.form_1.radio[1].checked = false;
¸ÃÐÐÖ¸ÁîָʾJavaScriptÔڸð´Å¥±»µã»÷ʱ¹Ø±ÕÁíÍâÒ»¸ö°´Å¥¡£ÓÉÓÚÁíÍâÒ»¸ö°´Å¥µÄº¯ÊýͬÕâ¸öºÜÏàËÆ£º
function onButton()
{
var the_box = window.document.form_1.radio[1];
if (the_box.checked == true)
{
window.document.form_1.radio[0].checked = false;
document.bgColor='white';
alert("Thanks!");
}
}
14. ÏÂÁÐÑ¡µ¥
<select name="pulldown_1" size=1>
<option>probiscus
<option>spider
<option>lemur
<option>chimp
</select>
×¢ÒâÕâ¸öÑ¡µ¥µÄÃû³ÆÊÇpulldown_1£¬µ«¸÷¸öÑ¡ÏîûÓÐÃû³Æ¡£ËùÒÔÒªµ÷ÓÃÆäÖеĸ÷¸öÑ¡ÏîÔòÓеãÀ§ÄÑ¡£
ÐÒºÃÊý×é¿ÉÒÔ°ïÖúÎÒÃǵ÷ÓÃÆäÖеÄÑ¡Ïî¡£Èç¹ûÄãÏë¸Ä±ä¸ÃÏÂÁÐÑ¡µ¥ÖеĵÚ2¸öÑ¡ÏÄã¿ÉÒÔÕâÑù×ö£º
window.document.form_1.pulldown_1.options[1].text = 'new_text';
ÕâÊÇÒòΪѡµ¥µÄÔªËØÓÐÒ»¸öÑ¡ÏîÊôÐÔ£¬¶ø¸ÃÊôÐÔÊÇÑ¡µ¥ËùÓÐÑ¡ÏîµÄ¼¯ºÏ¶ø³ÉµÄÊý×é¡£
³ýÁËÑ¡ÏîÊôÐÔ£¬Ñ¡µ¥»¹ÓÐÒ»ÏîÊôÐÔ½Ð×öselectedIndex¡£´ó±ÊÒ»¸öÑ¡ÏѡÔñºó£¬selectedIndexÊôÐÔ½«±ä³É±»Ñ¡ÏîµÄÊý×éË÷ÒýºÅ£¨ÐòÁкţ©¡£Ñ¡ÔñµÚ2¸öÁбíÑ¡µ¥ÖеÄÒ»¸öÑ¡ÏȻºó¼ì²éË÷ÒýºÅ¡£¼ÇסÊý×éÖеĵÚ1¸öÑ¡ÏîµÄË÷ÒýºÅÊÇ0¡£
<a href="#"box-sizing: border-box; color: rgb(51, 51, 51); font-family: arial, verdana, 'Microsoft YaHei', Tahoma, Simsun, sans-serif; line-height: 25.2px;">window.document.form_1.list_1.selectedIndex);
return false;">check the index.</a>
±íµ¥µÄÃû³ÆÊÇform_1£¬ÁбíÑ¡µ¥µÄÃû³ÆÊÇlist_1¡£selectedIndexÊôÐÔֵΪ
window.document.form_1.list_1.selectedIndex¡£Ä㻹¿É
ÒÔ½«selectedIndexÉèÖÃÈçÏ£º
window.document.form_1.list_1.selectedIndex = 1;
²¢¸ßÁÁ¶ÈÏÔʾµÚ2¸öÑ¡Ïî¡£Ò»µ©ÄãµÃµ½±»Ñ¡ÏîµÄË÷ÒýºÅ£¬Äã¾Í¿ÉÒÔ·¢ÏÖÆäÄÚÈÝ£º
var the_select = window.document.form_1.list_1;
var the_index = the_select.selectedIndex;
var the_selected = the_select.options[the_index].text;
15. »ñÈ¡select×é¼þµÄ±»Ñ¡ÖеÄÖµ
function getselected(){
var sel = document.form1.select;
return sel.options[sel.selectedIndex].text;
}
ÎÄÕÂ×ªÔØÓÚ£ºÇ°¶ËÍø
±¾ÎİæÈ¨¹éÀÖÓã²¥¿Íwebǰ¶Ë¿ª·¢ÅàѵѧԺËùÓУ¬»¶Ó×ªÔØ£¬×ªÔØÇë×¢Ã÷×÷Õß³ö´¦£¬Ð»Ð»£¡
×÷ÕߣºÀÖÓã²¥¿Íwebǰ¶Ë¿ª·¢ÅàѵѧԺ
Ê×·¢£ºhttp://www.itcast.cn/web/