0

我正在尝试创建一个基本的在线表单,根据选择的内容,表格的背景颜色会更改为适当的选项值。

我遇到的问题是提交表单时提交的是选项值,而不是我需要的文本。

有没有办法修改 onChange 或者完全有更好的方法?

谢谢你的帮助。

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Survey</title>
</head>

<body>

<table border="0" width="21%" cellspacing="0" cellpadding="0" height="20">
<tr>
    <td id = "mycell"> 
<p style="margin-top: 10px; margin-bottom: 10px"> 
<select name="q11" <select onChange="if(this.selectedIndex!=0)
document.getElementById('mycell').bgColor=this.options[this.selectedIndex].value">
<option value="#FFFFFF">Choose a factor...    
<option value="#F6B23E">My Company – feeling positive about who I work for
<option value="#F58386">My Leaders – being inspired by my business leaders 
<option value="#EF3135">My Boss – mutual respect and understanding
<option value="#F58386">My Team – enjoying who I work with
<option value="#AD6AA3">My Job – enjoying what I do
<option value="#95CAA0">My Personal Growth – learning, development and prospects 
<option value="#4FA761">My Deal – satisfaction with pay and benefits 
<option value="#95CAA0">My Wellbeing – having a balanced life 
</select></td>

4

2 回答 2

0

如果您想获取选项标签中存在的数据,请尝试使用:

.text()
or
innerhtml

javascript的功能。

于 2013-09-06T11:35:19.307 回答
0

您可以尝试像这样作弊:

获取类名而不是值

<select onChange="if(this.selectedIndex!=0)
document.getElementById('mycell').bgColor=this.options[this.selectedIndex].className">

并将颜色设置为className

<option value="My Company " class="#F6B23E">My Company – feeling positive about who I work for</option>

但不确定它是否跨兄弟,最重要的是,这是一个很好的方法,但它应该适合你。

于 2013-09-06T14:33:23.543 回答