动态更改功能参数 [英] Dynamically Change Function Parameters

查看:76
本文介绍了动态更改功能参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个动态更改表单验证脚本的函数

,具体取决于用户的选择。


表单onsubmit是:

onsubmit =" writevalidate(this.select.value); return document.MM_returnValue"


然后我有以下功能


函数writevalidate(selectvalue){

var1 =" \''form1 \'',\''type'\\''',\''# q \'',\''0'\\''','\\'''请输入你的

Type.\'',\''选择\'',\ ''#q\'',\''1 \'',\''请选择你的Status.\''" ;;

if(selectvalue ==''人'')

{

YY_checkform(''form1'',''type'',''#q'',''0'',''请输入您的

类型。'',''name'',''#q'',''0'',''请输入您的

名称' , 'select'',''#q'',''1'',''请选择你的状态。'');

}

else

{

YY_checkform(var1);

}

}


我我希望能够将我的表单参数动态写入

变量var1,然后将它们插入到函数中。


var1 =" ; \''form1 \'',\'''\\''',\''#q \'',\''0'\\''','\\'''请输入你的

类型。\'',\''选择\'',\''#q \'',\''1 \'',\''请发布选择你的状态。\''" ;;

YY_checkform(var1);


但目前它不起作用。


我该怎么做?


谢谢,

Wayne C.

I''m writing a function to dynamically change a form validation script
depending upon the user''s choices.

The form onsubmit is:
onsubmit="writevalidate(this.select.value);return document.MM_returnValue"

I then have the following function

function writevalidate(selectvalue) {
var1 = "\''form1\'',\''type\'',\''#q\'',\''0\'',\''Please enter your
Type.\'',\''select\'',\''#q\'',\''1\'',\''Please select your Status.\''";
if (selectvalue==''Person'')
{
YY_checkform(''form1'',''type'',''#q'',''0'',''Please enter your
Type.'',''name'',''#q'',''0'',''Please enter your
name'',''select'',''#q'',''1'',''Please select your Status.'');
}
else
{
YY_checkform(var1);
}
}

I''d like to be able to dynamically write my form parameters into the
variable var1 and then insert them into the function like so.

var1 = "\''form1\'',\''type\'',\''#q\'',\''0\'',\''Please enter your
Type.\'',\''select\'',\''#q\'',\''1\'',\''Please select your Status.\''";
YY_checkform(var1);

But currently it doesn''t work.

How do I do this?

Thanks,
Wayne C.

推荐答案

2006-01-20,Wayne Cressman< WC ******* @ etelligence.com>写道:
On 2006-01-20, Wayne Cressman <WC*******@etelligence.com> wrote:
var1 =" \''form1 \'',\''type \'',\''#q \'', ''''''','\\'''请输入你的类型。\'',\''选择\'',\''#q \'',\ ''1'\\'','\\'''请选择你的状态。\''" ;;
YY_checkform(var1);

但目前它不起作用。

我该怎么做?
var1 = "\''form1\'',\''type\'',\''#q\'',\''0\'',\''Please enter your
Type.\'',\''select\'',\''#q\'',\''1\'',\''Please select your Status.\''";
YY_checkform(var1);

But currently it doesn''t work.

How do I do this?




eval(" YY_checkform(" + var1 +");");


再见。

Jasen



eval("YY_checkform("+var1+");");

Bye.
Jasen


Wayne Cressman写道:
Wayne Cressman wrote:
I ''正在编写一个函数来动态更改表单验证脚本
取决于用户的选择。

表单onsubmit是:
onsubmit =" writevalidate(this .select.value); return document.MM_returnValue"

然后我有以下功能

函数wr itevalidate(selectvalue){
var1 =" \''form1 \'',\''type \'',\''#q \''',\''0 \\'',\''请输入你的类型。\'',\''选择\'',\''#q \''',\''1 \ '',\''请选择你的状态。\''" ;;


您可以在双打内嵌单引号,反之亦然,而不需要

报价。并且不要让发布的代码自动换行,手动换行大约

70个字符:


var1 ="''form1'', ''输入'',''#q'',''0'',''请输入您的

+类型。'',''选择'','' #q'',''1'',''请选择你的状态。''" ;;

但我认为这不是你想做的事。


if(selectvalue ==''Person'')
{YY_checkform(''form1'',''type'',''#q'', ''0'',''请输入您的
类型。'',''名称'',''#q'',''0'',''请输入您的
名称' ',''选择'',''#q'',''1'',''请选择你的状态。'';
}

{
YY_checkform(var1);
}

我希望能够将表单参数动态写入
变量var1 a然后将它们插入到函数中,就像这样。


看来你想要的是应用不同的验证规则

,具体取决于用户选择或输入的内容。如果您描述

条件是什么,可能会提供一些帮助。


通常验证规则保持简单和硬编码,因为

客户端验证不可靠。有效地设计表单并且

依赖于服务器端验证,客户端对用户来说非常好

(如果操作正确,它可能是一个真正的痛苦)和节省一些带宽。


var1 =" \''form1 \'',\''type'\\''',\''#q'\\'' ,\'''\\'','\\'''请输入你的类型。\'',\''选择\'',\''#q \'', \'''\\''','\\'''请选择你的状态。\''" ;;
YY_checkform(var1);

但目前它并没有工作。
I''m writing a function to dynamically change a form validation script
depending upon the user''s choices.

The form onsubmit is:
onsubmit="writevalidate(this.select.value);return document.MM_returnValue"

I then have the following function

function writevalidate(selectvalue) {
var1 = "\''form1\'',\''type\'',\''#q\'',\''0\'',\''Please enter your
Type.\'',\''select\'',\''#q\'',\''1\'',\''Please select your Status.\''";
You can nest single quotes inside doubles and vice versa without
quoting. And don''t let posted code auto-wrap, manually wrap it at about
70 characters:

var1 = "''form1'',''type'',''#q'',''0'',''Please enter your "
+ "Type.'',''select'',''#q'',''1'',''Please select your Status.''";
But I don''t think that is what you want to do anyway.

if (selectvalue==''Person'')
{
YY_checkform(''form1'',''type'',''#q'',''0'',''Please enter your
Type.'',''name'',''#q'',''0'',''Please enter your
name'',''select'',''#q'',''1'',''Please select your Status.'');
}
else
{
YY_checkform(var1);
}
}

I''d like to be able to dynamically write my form parameters into the
variable var1 and then insert them into the function like so.
It seems that what you want is to apply different validation rules
depending on what the user has selected or entered. If you describe
what the conditions are, maybe some help can be provided.

Usually validation rules are kept simple and hard-coded since
client-side validation is unreliable. Design the form efficiently and
rely on server-side validation, client-side is just nice for the user
(if done properly, it can be a real pain) and saves some bandwidth.

var1 = "\''form1\'',\''type\'',\''#q\'',\''0\'',\''Please enter your
Type.\'',\''select\'',\''#q\'',\''1\'',\''Please select your Status.\''";
YY_checkform(var1);

But currently it doesn''t work.




什么结果适合你对''工作'的定义?


[...]

-

Rob



What result would fit your definition of ''work''?

[...]
--
Rob


Jasen Betts写道:
Jasen Betts wrote:
2006年-01-20,Wayne Cressman< WC ******* @ etelligence.com>写道:
On 2006-01-20, Wayne Cressman <WC*******@etelligence.com> wrote:
var1 =" \''form1 \'',\''type \'',\''#q \'',\''0 \'',\''请输入你的类型。\'',\''选择\'',\''#q \'',\''1 \\'',\''请选择你的状态。\''" ;;


没有必要在'-delimited字符串文字中转义'

YY_checkform(var1);

但是目前它不起作用。

我该怎么做?
var1 = "\''form1\'',\''type\'',\''#q\'',\''0\'',\''Please enter your
Type.\'',\''select\'',\''#q\'',\''1\'',\''Please select your Status.\''";
Escaping '' within a "-delimited string literal is not necessary.
YY_checkform(var1);

But currently it doesn''t work.

How do I do this?



eval(" YY_checkform(" + var1 +");" );



eval("YY_checkform("+var1+");");




eval是邪恶的[tm]。


YY_checkform.apply(this,var1.split(", ));

PointedEars



eval is evil[tm].

YY_checkform.apply(this, var1.split(","));
PointedEars


这篇关于动态更改功能参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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