下面的代码创建一个表单,并将数组列表附加到提交的字段集。但是,只有在表单中输入0到3的值而不是数组变量ArrayName =['list1','list2','list3','list4']
中的实际文本值时,它才有效
这行代码:var a = ArrayName.indexOf(form.url.value)
是返回值-1而不是文本输入值。
非常感谢任何帮助。
<font color = "Silver" size ="4">
<form onsubmit="return processForm(this);">
<input type="text" name="url" required="required"/>
<input type ="radio"name="SearchType" value ="SymbolSearch" id="SearchByEpic" checked ="checked"/><font size=2>Symbol search
<input type ="radio"name="SearchType" value ="CompanySearch"/>Company name search
<input type="submit" value="Submit" />
</input></input>
</form><font color = "white">
<br><br>
<style media="screen" type="text/css">
fieldset{
border:0px solid gray;
padding:1em;
float:left;
font-family:Arial;
}
legend{
display:none;
}
h2{
border-bottom:2px solid gray;
margin:1em 0;
}
p{
margin:1em 0;
}
</style>
<div id="QuoteField">
<fieldset style="float: center; background-color:#313131; width:558px; height:318px;" > <font size="4"><strong>
<br><br><br><br>
<li><p id="CompanyName"><font color=#21F1FE><strong>Company name: </p></li>
<li><p id="CompanyEpic"><font color=#21F1FE><strong>Stock symbol: </p></li>
<li><p id="CompanySector"><font color=#21F1FE>Sector: </p></li>
<li><p id="CompanySub">Sub sector: </p></li>
<br>
</fieldset></div>
<script type="text/javascript">var your_url = 'http://getquote=LLOY.L';</script>
<script type="text/javascript" src="jquery.min.js" ></script>
<script type="text/javascript">
$('#QuoteField').hide();
var ArrayName = ['List1','List2','List3','List4']
var ArrayDate = ['28-03-1991', '28-09-2004', '01-01-1901', '12-05-2008']
var ArraySector = ['General Financial','Nonlife Insurance','Support Services','Oil Equipmen']
var EpicSubSector = ['Asset Managers','Insurance Brokers','General Support','Oil Equipment & Services']
var Epic=['stock1','stock2','stock3','stock4']
function processForm(form)
{
var somevalue = form.url.value;
var StockNum=0;
var a = ArrayName.indexOf(form.url.value);
alert( a );
$('#QuoteField').show(500);
$('#CompanyName').html('<font color=#21F1FE><strong>Company name: ');
$('#CompanySub').html('Sub sector: ');
$('#CompanySector').html('Sector: ');
$('#CompanyEpic').html('Stock symbol: ');
//
if($('#SearchByEpic').attr('checked'))
{
$('#CompanyName').append('</strong><font color="white" size="2"</font>' + ArrayName[form.url.value] +'<strong>');
$('#CompanySub').append('</strong><font color="white" size="2"</font>' + ArrayDate[form.url.value]);
$('#CompanySector').append('</strong><font color="white" size="2">' + ArraySector[form.url.value]+ '</font>');
$('#CompanyEpic').append('</strong><font color="white" size="2">' + Epic[form.url.value]+ '</font>');
}
else{alert("not epic search");$("#symbol").html("")
}
//window.open("http://www.reuters.com/finance/stocks/overview?symbol=" + form.url.value, "test window","width=100,height=100");
return false;
return false;
}
</script>
答案 0 :(得分:0)
当我尝试使用您的代码时,它的工作正常。
最小的工作示例:
HTML:
<form onsubmit="return processForm(this);">
<input type="text" name="url" required="required" value="List1" />
<input type="submit" value="Submit" />
</form>
使用Javascript:
var ArrayName = ['List1', 'List2', 'List3', 'List4'];
function processForm(form) {
var somevalue = form.url.value;
var a = ArrayName.indexOf(form.url.value);
alert(a);
return false;
}
小提琴:http://jsfiddle.net/Guffa/Ap9Gw/
您的代码有很多错误,但我看到的任何内容都不会使脚本的这一部分无法正常工作。