我申请表格,使用jquery& php邮件,但无法解决最后一个问题,这里是选择选项:
<select name="LV01S01F001" id="LV01S01F001" class="selectform">`
<option disabled="disabled" selected="selected">choose one</option>
<option value="ID001">01 - option name + short description</option>
<option value="ID002">02 - option name + short description</option>
<option value="ID003">03 - option name + short description</option>
</select>
因此,通过选择的选项,使用它的值,它将使用以下脚本打开隐藏的DIV:
<script type="text/javascript">
$(function() {
$('#LV01S01F001').change(function(){
$('.CREDITDIV').hide();
$('#' + $(this).val()).show();
});
});
</script>
问题Poinf,该脚本使用选择选项值,同时值由 php mail 发送,但我需要发送它的文字,但不是它的价值,所以让它看起来像:
<option>01 - option name + short description</option>
因此它会发送 01 - 选项名称+简短描述,但不会发送 ID001 作为其价值。
或更改值
<option value="ID003">
还有其他什么?
提前谢谢!
答案 0 :(得分:0)
尝试 .text(),如
<script type="text/javascript">
$(function() {
$('#LV01S01F001').change(function(){
$('.CREDITDIV').hide();
$('#' + $(this).val()).text($(this).find('option:selected').text());
$('#' + $(this).val()).show();
});
});
</script>
但最好只使用其值,而不是我们选择的文本。请参阅LINK
答案 1 :(得分:0)
要获取所选选项的文字 ,请使用:
$(this).find('option:selected').text();
this
指的是<select>
例如:
$('.selectform').change(function() {
alert($(this).find('option:selected').text());
});