JavaScript Replace()方法 [英] JavaScript Replace() Method

查看:52
本文介绍了JavaScript Replace()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道在ASP表单中使用JavaScript string.replace()方法的好方法?


以下是场景:


我有一个不能接受撇号的表格。我想使用replace(),这样撇号就可以自动替换为两个''''。原因是 - SQL Server不喜欢将撇号发送到数据库。


我已经尝试在ASP页面的SQL区域的服务器端执行此操作功能(有一些很大的帮助)

但我似乎可以让它工作。这就是我想在客户端尝试的原因。

我已经尝试过了,而且replace()方法确实有效。问题是表单有一个Action =" bla.asp"

这是重定向页面。但页面没有重定向,因为在输入标签中,我有一个onclick ="返回

stringReplace(this.form)"


所以这是我的delimma - 我希望能够在重定向到另一个.asp页面之前替换该字符。


任何想法?以下是代码:

------------------------------------- --------------

< html>

< head>

< title> Untitled Document< / title>

< meta http-equiv =" Content-Type"含量=" text / html的; charset = iso-8859-1">


< script language =" javascript">


function stringReplace(form) {

var replaceStr = form.textfield1.value

var pattern = / \''/ g;

form.textfield1.value = replaceStr.replace(pattern,"''''");

}

< / script>


< / head>


< body>


< form name =" form1"方法= QUOT;交" action =" JStest_redirect.asp">

< p> fname:

< input type =" text"命名= QUOT; textfield1的" size =" 20">

< / p>

< p> lname:

< input type ="文本"命名= QUOT;文本字段2" size =" 20">

< / p>

< p>

< input onclick =" return stringReplace (形式)"类型= [提交"命名= [提交" value =" Submit">

< / p>


< / form>

< / body> ;

< / html>

Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form?

Here is the scenario:

I have a form that cannot accept apostrophes. I want to use the replace() so that the apostrophe is
automatically replace with two '''' . Reason being--SQL Server does not like apostrophes being sent to database.

I''ve tried to do this on the server side in the SQL area of the ASP page by writing a function (with some great help)
but I can seem to get it to work. That''s is why I want do try on the client side.

I''ve already made an attempt and the replace() method does work. The problem is the form has an Action = "bla.asp"
This is the redirect page. But the page doesn''t redirect because in the Input tag, I have an onclick = "return
stringReplace(this.form)"

So here is my delimma--I want to be able to replace the character before it redirects to the other .asp page.

Any ideas? Below is the code:
---------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript">

function stringReplace(form) {
var replaceStr = form.textfield1.value
var pattern = /\''/g;
form.textfield1.value = replaceStr.replace(pattern, "''''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_redirect.asp">
<p>fname:
<input type="text" name="textfield1" size="20">
</p>
<p>lname:
<input type="text" name="textfield2" size="20">
</p>
<p>
<input onclick="return stringReplace(form)" type="submit" name="Submit" value="Submit">
</p>

</form>
</body>
</html>

推荐答案

您可以将stringReplace方法作为onBlur处理程序调用每个

控制需要它 - 但你尝试做这个服务器端是正确的方法 - 向我们展示你的服务器端代码是不行的。


艾伦


" Barnes" <巴**** @ discussions.microsoft.com>在留言中写道

新闻:9B ********************************** @ microsof t.com ...
You could call your stringReplace method as the onBlur handler for each
control needing it - but your attempt to do this server-side is the correct
way approach - show us your server-side code that wasn''t working.

Alan

"Barnes" <Ba****@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
有没有人知道在ASP表单中使用JavaScript string.replace()
方法的好方法?
以下是场景:

我有一个不能接受撇号的表格。我想使用replace()
,以便撇号自动替换为两个''''。原因是 - SQL Server不喜欢将
撇号发送到数据库。
我已经尝试在ASP页面的SQL区域的服务器端执行此操作
功能(有一些很大的帮助),但我似乎可以让它工作。这就是我想要尝试
客户端的原因。我已经尝试过了,而且replace()方法确实有效。
问题是表单有一个Action =" bla.asp"这是重定向页面。但页面没有重定向,因为在
输入标签中,我有一个onclick =" return stringReplace(this.form)"

所以这是我的delimma - 我希望能够在
之前替换字符,它会重定向到另一个.asp页面。
任何想法?以下是代码:
----------------------------------------- ----------
< html>
< head>
< title> Untitled Document< / title>
< meta http-equiv = QUOT;内容类型"含量=" text / html的; charset = iso-8859-1">

< script language =" javascript">

函数stringReplace(form){
var replaceStr = form.textfield1.value
var pattern = / \''/ g;
form.textfield1.value = replaceStr.replace(pattern,"''''");
}
< / script>
< / head>

< body>

< form name =" form1的"方法= QUOT;交" action =" JStest_redirect.asp">
< p> fname:
< input type =" text"命名= QUOT; textfield1的" size =" 20">
< / p>
< p> lname:
< input type =" text"命名= QUOT;文本字段2" size =" 20">
< / p>
< p>
< input onclick =" return stringReplace(form)"类型= [提交"命名= [提交"
value =" Submit"> < / p>

< / form>
< / body>
< / html>
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form?
Here is the scenario:

I have a form that cannot accept apostrophes. I want to use the replace() so that the apostrophe is automatically replace with two '''' . Reason being--SQL Server does not like apostrophes being sent to database.
I''ve tried to do this on the server side in the SQL area of the ASP page by writing a function (with some great help) but I can seem to get it to work. That''s is why I want do try on the client side.
I''ve already made an attempt and the replace() method does work. The problem is the form has an Action = "bla.asp" This is the redirect page. But the page doesn''t redirect because in the Input tag, I have an onclick = "return stringReplace(this.form)"

So here is my delimma--I want to be able to replace the character before it redirects to the other .asp page.
Any ideas? Below is the code:
---------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript">

function stringReplace(form) {
var replaceStr = form.textfield1.value
var pattern = /\''/g;
form.textfield1.value = replaceStr.replace(pattern, "''''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_redirect.asp">
<p>fname:
<input type="text" name="textfield1" size="20">
</p>
<p>lname:
<input type="text" name="textfield2" size="20">
</p>
<p>
<input onclick="return stringReplace(form)" type="submit" name="Submit" value="Submit"> </p>

</form>
</body>
</html>



=?Utf-8?B?QmFybmVz?=写于2004年7月2日在

microsoft.public.inetserver.asp.general:
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
microsoft.public.inetserver.asp.general:
我'已经尝试过,而且replace()方法确实有效。
问题是表单有一个Action =" bla.asp"这是重定向页面。但页面没有重定向,因为在Input标签中,我有一个onclick =" return stringReplace(this.form)"


只需跳过return字样即可像这样:


onclick =" stringReplace(this.form)"

所以这是我的delimma - 我希望能够替换字符
在重定向到另一个.asp页面之前。
I''ve already made an attempt and the replace() method does work. The
problem is the form has an Action = "bla.asp" This is the redirect
page. But the page doesn''t redirect because in the Input tag, I have
an onclick = "return stringReplace(this.form)"
Just skip the word "return" like this:

onclick = "stringReplace(this.form)"
So here is my delimma--I want to be able to replace the character
before it redirects to the other .asp page.




你不应该问这个NG的客户问题,真的。


这就像要求巴士公司如何修理自己的车一样,因为你计划先乘坐公共汽车或下次乘坐公共汽车。


-

Evertjan。

荷兰。

(请将x''es更改为我的电子邮件地址中的点数)



You should not ask a clientside question on this NG, really.

It is like asking the bus company how to repair your own car,
because you planned to go by bus first or next time.

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


我如何检查所有文本字段,而不仅仅是第一个文本字段。


下面代码中的空白将是文本字段名称的位置会去,但我可以推广这个名字吗?我已经尝试过文本,输入,输入...但我不确定这里会有什么JavaScript名称。另外,如果我使用onblur,我可以使用相同的函数,还是必须为每个textfeild创建一个函数 - 这太多了。


函数stringReplace(form){

var replaceStr = form .______。value

var pattern = / \''/ g;

form ._______。value = replaceStr .replace(pattern,"''''");

}

< / script>


谢谢你事先得到了你的帮助!


" Alan Howard"写道:
How would I check for all textfields, not just the first one.

The blank in the code below would be where the textfield name would go but can I generalize this name? I''ve tried text, type, input...but I''m not sure what JavaScript name would go here. Also, If I use onblur, can I use the same function or do I have to make a function for every textfeild--this would be too much.

function stringReplace(form) {
var replaceStr = form.______.value
var pattern = /\''/g;
form._______.value = replaceStr.replace(pattern, "''''");
}
</script>

Thank you in advance for your help!

"Alan Howard" wrote:
您可以将stringReplace方法称为需要它的每个
控件的onBlur处理程序 - 但是您尝试执行此服务器端是正确的
方法 - 告诉我们你的服务器端代码是不行的。

Alan

" Barnes" <巴**** @ discussions.microsoft.com>在消息中写道
新闻:9B ********************************** @ microsof t.com。 ..
You could call your stringReplace method as the onBlur handler for each
control needing it - but your attempt to do this server-side is the correct
way approach - show us your server-side code that wasn''t working.

Alan

"Barnes" <Ba****@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
有没有人知道在ASP表单中使用JavaScript string.replace()
Does anyone know of a good way to use the JavaScript string.replace()


方法的好方法?


method in an ASP form?


我有一个不能接受撇号的表格。我想使用replace()

Here is the scenario:

I have a form that cannot accept apostrophes. I want to use the replace()


使撇号

自动替换为两个''''。原因是 - SQL Server不喜欢将
automatically replace with two '''' . Reason being--SQL Server does not like


撇号发送到数据库。


apostrophes being sent to database.


我试图在SQL的服务器端执行此操作ASP页面的区域

I''ve tried to do this on the server side in the SQL area of the ASP page


通过编写一个函数(有一些很好的帮助)


by writing a function (with some great help)

但我似乎可以让它工作。这就是我想要尝试
but I can seem to get it to work. That''s is why I want do try on the


客户端的原因。


client side.


我已经尝试过了,而且replace()方法做了工作。

I''ve already made an attempt and the replace() method does work. The


问题是表单有一个Action =" bla.asp"


problem is the form has an Action = "bla.asp"

这是重定向页面。但页面没有重定向,因为在
This is the redirect page. But the page doesn''t redirect because in the


输入标签中,我有一个onclick =" return


Input tag, I have an onclick = "return

stringReplace(this.form)"

所以这是我的delimma - 我希望能够在
stringReplace(this.form)"

So here is my delimma--I want to be able to replace the character before

之前替换字符,然后重定向到另一个.asp页面。


it redirects to the other .asp page.


有任何想法吗?以下是代码:
----------------------------------------- ----------
< html>
< head>
< title> Untitled Document< / title>
< meta http-equiv = QUOT;内容类型"含量=" text / html的; charset = iso-8859-1">

< script language =" javascript">

函数stringReplace(form){
var replaceStr = form.textfield1.value
var pattern = / \''/ g;
form.textfield1.value = replaceStr.replace(pattern,"''''");
}
< / script>
< / head>

< body>

< form name =" form1的"方法= QUOT;交" action =" JStest_redirect.asp">
< p> fname:
< input type =" text"命名= QUOT; textfield1的" size =" 20">
< / p>
< p> lname:
< input type =" text"命名= QUOT;文本字段2" size =" 20">
< / p>
< p>
< input onclick =" return stringReplace(form)"类型= [提交" name =" Submit"

Any ideas? Below is the code:
---------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript">

function stringReplace(form) {
var replaceStr = form.textfield1.value
var pattern = /\''/g;
form.textfield1.value = replaceStr.replace(pattern, "''''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_redirect.asp">
<p>fname:
<input type="text" name="textfield1" size="20">
</p>
<p>lname:
<input type="text" name="textfield2" size="20">
</p>
<p>
<input onclick="return stringReplace(form)" type="submit" name="Submit"


value =" Submit">


value="Submit">

< / p>

< / form>
< / body>
< / html>
</p>

</form>
</body>
</html>




这篇关于JavaScript Replace()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆