在一个javascript文件里可以再写入的javascript判断代码吗?

twtetgso 2004-11-23 02:45:08
比如有一个head.js文件,里面内容如下:
document.write("<table width=100% border=0 cellspacing=0 cellpadding=0>")
document.write(" <tr>")
document.write(" <td width=100% align=center><img src=http://images/fj_r1_c2.jpg width=802 height=30 border=0 usemap=#Map></td>")
document.write(" </tr>")
document.write("</table>")
........
document.write(" <input name=usernameshow type=text class=in size=6 maxlength=15> ")
........


其中上面....部分是一些省略的form内的代码,
我想再在里面写入一些代码,打开页面usernameshow自动获得焦点,如下:

document.write("<SCRIPT language=javascript>")
document.write("<!--")
document.write("function window_onload() {")
document.write(" usernameshow.focus();")
document.write("}")
document.write("//-->")
document.write("</SCRIPT>")

这样可以吗?我试了,不行,usernameshow没有获得焦点,但也没有提示错误,应该怎么写?
...全文
130 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
haoya1 2004-12-17
  • 打赏
  • 举报
回复
在JavaScript里以document.write方式直接重载是不可以的,想再重载必须在外部调用。
oubao 2004-11-24
  • 打赏
  • 举报
回复
<body onload="document.myForm.usernameshow.focus();">这样就行了
oubao 2004-11-24
  • 打赏
  • 举报
回复
你在进入页面的时候调用window_onload()这个函数了吗?
twtetgso 2004-11-23
  • 打赏
  • 举报
回复
我试过了,不行啊
jackywoo 2004-11-23
  • 打赏
  • 举报
回复
document.write("<SCRIPT language=javascript>")
document.write("<!--")
document.write("function window_onload() {")
document.write(" document.form1.usernameshow.focus();") //写上form名称
document.write("}")
document.write("//-->")
document.write("</SCRIPT>")

试试
u2g2000 2004-11-23
  • 打赏
  • 举报
回复
document.write("<SCRIPT language=javascript>")
document.write(" usernameshow.focus();")
document.write("</SCRIPT>")

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧