【发布时间】:2012-11-21 11:10:50
【问题描述】:
我正在使用 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 中的语言根据他们从下拉列表中选择的项目而改变。
提前致谢。 :)
【问题讨论】:
-
看起来应该对我有用。有什么问题?
-
当我进行选择时,文本区域中没有显示任何内容。我可以链接表单,但它是一个多页表单,并且特定字段非常深入(所以要访问 PITA)。
-
好的,尝试调试:如果您还没有 firebug,请获取它并与 firefox 一起使用。然后将下面这行
console.log(divetext)放在var divetext = $('#input_27').val();下,看看值是多少。问题可能出在某个地方。或者尝试手动设置divetext,以便找出问题所在 -if条件或divetext值的设置。 -
控制台中没有显示关于潜水文本的任何内容。
-
使用 firebug 的控制台,在命令行(底部)输入:
console.log($('#input_27').val();)。如果那是空的,那么你的#input_27没有传递任何值,你就发现了你的问题。发布您的 html 结构也会有所帮助。
标签: jquery forms wordpress gravity