需要返回字符串并编写通用脚本 [英] Need to return string and write generic script

查看:67
本文介绍了需要返回字符串并编写通用脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< disclaimer> js newbie< / disclaimer>


我的页面有一个由几个单选按钮组成的表单。我想轮询

按钮来确定选择了哪个按钮并将其值转换为

字符串。然后我想在同一页面上使用该字符串。


我的脚本是:


function checkRadio(field){

for(var i = 0; i< field.length; i ++){

if(field [i] .checked)return field [i] .value;

}

返回false;

}

函数checkFormLeft()

{

if(radioValue = checkRadio(form1.p1_p6_left)){

if(radioValue == 0){$ syml =''Uniform Thermal Pattern'';}

if(radioValue == 10){$ syml =''常规热血管模式'';}

if(radioValue == 20){$ syml =''thermovascular network'';}

if(radioValue == 25){$ syml =''不规则热血管

模式'';}

if(radioValue == 40) {$ syml =''扭曲的热血管

模式'';}

if(radioValue == 60){$ syml =''anarchic thermovascular pattern'';}

alert(" you selected" + $ syml);

}

}


我使用onClick =" checkForm()来调用脚本


我添加了警报,以便我可以验证脚本正在运行。它是,但是当我尝试在调用脚本的页面上使用$ syml时,我得到了

没有,例如,''静脉是$ syml。' '给我''静脉。''


如何使用字符串?


问题2:


我有几个页面有多个无线电(和复选框)数组。我希望

为所有这些使用单个js脚本。上面

中的''p1_p6_left''是单选按钮数组的通用名称。我怎么写

''checkRadio(form1.p1_p6_left)''所以我可以传递不同的值代替

p1_p6_left?


TIA(再次)


-

Ed Jay(删除M以通过电子邮件回复)

<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {
if (radioValue == 0) {$syml = ''Uniform Thermal Pattern'';}
if (radioValue == 10) {$syml = ''regular thermovascular pattern'';}
if (radioValue == 20) {$syml = ''thermovascular network'';}
if (radioValue == 25) {$syml = ''irregular thermovascular
pattern'';}
if (radioValue == 40) {$syml = ''distorted thermovascular
pattern'';}
if (radioValue == 60) {$syml = ''anarchic thermovascular pattern'';}
alert("You selected " + $syml);
}
}

I call the script using onClick="checkForm()"

I added the alerts so I could verify the script is working. It is, but
when I try to use either $syml on the page calling the script, I get
nothing, e.g., ''The veins are $syml.'' gives me ''The veins are.''

How do I use the string?

Question 2:

I have several pages with multiple radio (and checkbox) arrays. I''d like
to use a single js script for all of them. The ''p1_p6_left'' in the above
is the common name of the radio button array. How do I write
''checkRadio(form1.p1_p6_left)'' so I can pass different values in place of
p1_p6_left?

TIA (again)

--
Ed Jay (remove M to respond by email)

推荐答案

syml =''Uniform Thermal Pattern'';}

if(radioValue == 10){
syml = ''Uniform Thermal Pattern'';}
if (radioValue == 10) {


syml = ''常规热血管模式'';}

if(radioValue == 20){
syml = ''regular thermovascular pattern'';}
if (radioValue == 20) {


syml =''thermovascular network'';}

if(radioValue == 25){
syml = ''thermovascular network'';}
if (radioValue == 25) {


这篇关于需要返回字符串并编写通用脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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