我正在尝试从隐藏字段中获取值。
这是由Visualforce页面(Salesforce)吐出的HTML(动态生成ID)
<div style="width:300px;position:relative" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:optableAccount">
<!-- Need value for below field to be alerted -->
<input type="hidden" value="001i0000008LDtv" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid">
<input type="hidden" value="Aethna Home Products" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkold" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkold">
<input type="hidden" value="001" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lktp" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lktp">
<input type="hidden" value="0" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lspf" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lspf">
<input type="hidden" value="0" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lspfsub" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lspfsub">
<input type="hidden" value="1" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_mod" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_mod"><span class="lookupInput">
<!-- I do get the value of below field -->
<input type="text" size="20" onchange="getElementByIdCS('massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid').value='';getElementByIdCS('massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_mod').value='1';" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup" maxlength="255" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup">
<script>new ForeignKeyInputElement("massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup","/_ui/common/data/LookupValidationServlet",null,true,{"acent":"001"});</script><a title="Account Name Lookup (New Window)" onclick="setLastMousePosition(event)" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkwgt" href="javascript:%20openLookup%28%27%2F_ui%2Fcommon%2Fdata%2FLookupPage%3Flkfm%3DmassConvertwithInputs%253ApbmconvertInput%253ApbformmconvertInput%26lknm%3DmassConvertwithInputs%253ApbmconvertInput%253ApbformmconvertInput%253ApbsmconvertInput%253Apbspbtable%253A0%253AaccountLookup%26lktp%3D%27%20%2B%20getElementByIdCS%28%27massConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3AaccountLookup_lktp%27%29.value%2C670%2C%271%27%2C%27%26lksrch%3D%27%20%2B%20escapeUTF%28getElementByIdCS%28%27massConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3AaccountLookup%27%29.value.substring%280%2C%2080%29%29%29"><img title="Account Name Lookup (New Window)" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" alt="Account Name Lookup (New Window)" src="/s.gif"></a></span><select style="width:148px" size="1" class="accSelectandlookup" name="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:convertedStatus" id="massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:convertedStatus"> <option value="000000000000000000">Create New Account: Greenwich Media</option>
</select></div>
这是jquery代码我正在使用警报值
<script>
$(document).ready(function () {
$('form :input[id$="accountLookup"]').change(function() {
$('form :input[id$="accountLookup"]').each(function () {
var str= $(this).attr("id") + "_lkid";
alert($(str).val());// This alert shows undefined
alert($(this).val());// This shows the Aethna Home Products which correct
alert($('massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid').val()); // This shows undefined
});
});
$('form :input[id$="accountLookup"]').change(function() {
$('form :input[id$="accountLookup_lkid"]').each(function () {
alert($(this).val()); // This shows a blank value
});
});
});
</script>
我需要获取字段massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid
我已经用每个警报当前投掷的内容评论了jquery脚本
知道我做错了吗?
答案 0 :(得分:4)
你错过了选择器中的#:
alert($("#massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid").val());
同样在这里
var str= '#' + $(this).attr("id") + "_lkid";
alert($(str).val());
答案 1 :(得分:0)
当您使用id作为选择器时,您需要使用#
。如果它是类,则使用.
作为选择器
$('massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid').val()
与
$('#massConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:accountLookup_lkid').val()