我正在使用WordPress的Gravity Forms插件,我正在尝试让其中一个选择菜单动态更新textarea中的文本。我是jQuery的新手,我非常感谢帮助理解如何使我的代码工作。
<script type="text/javascript">
$(document).ready(function() {
$('#input_27').change(function() {
var divetext = $('#input_27').val();
var divewords = '';
if (divetext == 'Standard') {
divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen. On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board at that time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
}
else if (divetext == '1st Dive') {
divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen. On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board for their 1st Dive was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
}
else if (divetext == 'Last Dive') {
divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen. On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board for their last time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
}
else if (divetext == 'Honorary Submariner') {
divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen. On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board at that time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
}
else {
divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen. On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board at that time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
}
$("#input_20").val(divewords);
});
});
</script>
(代码也在:http://pastie.org/pastes/5476003)
input_27 - 选择菜单的ID。 input_20 - 文本区域的ID。
简而言之,我希望textarea中的语言根据他们从下拉列表中选择的项目进行更改。
提前致谢。 :)
答案 0 :(得分:0)
请试一试。
请替换此代码:
var divetext = $('#input_27').val();
要
var divetext = $('#input_27:selected').text();