Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » AJAX讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 新手请教关于字符串对象替换的问题
willghost





发贴: 1
于 2007-11-11 21:50 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
新学js,学校教材差的要死,要用的书上根本没有。
这周的js作业是用替换字符串对象
之前讲了查找字符串对象,我自己在网上找了字符串对象替换的方法replace及它的用法可自己改怎么也改不对,请高手赐教。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function index()
{
  var str1=document.form1.strings1.value;
  var str2=document.form2.strings2.value;
  var s=str2.indexOf(str1);
  if(s!=-1&&str1!="")
  alert("已经找到该字符");
  else alert("没有找到字符");
  }
function thtest()
{  var th1=document.form1.strings1.value;
  var th2=document.form2.strings2.value;
  var th3=document.form3.strings3.value;
  var a=th2.replace(/th2/,"th3");
}
  </script>
</head>
<body>
<center>
<form name="form1">
请输入查找的内容:
<input type="text" name="strings1" size="20">
<input type="button" value="查找" onclick="index()"><br>
</form>
<form name="form2">
<textarea name="strings2" rows="5" cols="30"></textarea>
</form>
<form name="form3">
<input type="text" name="strings3" size="20">
<input type="button" value="替换" onclick="thtest()"><br>
   </form>
</center>
</body>
</html>




话题树型展开
人气 标题 作者 字数 发贴时间
13848 新手请教关于字符串对象替换的问题 willghost 1258 2007-11-11 21:50

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923