我正在尝试创建一个基本的在线表单,根据选择的内容,表格的背景颜色会更改为相应的选项值。
我遇到的问题是提交表单时正在提交选项值而不是我需要的文本。
有没有办法修改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>
答案 0 :(得分:0)
如果您想获取选项标记内的数据,请尝试使用:
.text()
or
innerhtml
javascript的功能。
答案 1 :(得分:0)
获取className而不是value
<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>
但不确定它是否是跨兄弟,最重要的是,这是一个很好的方法,但它应该适合你。