Jquery 捕获通过javascript对字段所做的更改
以下是我面临的问题的背景 我有一个Visualforce页面(Salesforce),它有一个查找字段 查找字段是一组隐藏字段、一个普通输入字段和带有href的图像,可打开一个弹出窗口供用户选择。每个选定值有2个值Jquery 捕获通过javascript对字段所做的更改,jquery,Jquery,以下是我面临的问题的背景 我有一个Visualforce页面(Salesforce),它有一个查找字段 查找字段是一组隐藏字段、一个普通输入字段和带有href的图像,可打开一个弹出窗口供用户选择。每个选定值有2个值 所选值的名称 所选值的id 名称存储在非隐藏输入字段中,并存储在以lkid结尾的hiddenfield中。Html如下所示 <div id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLea
<div id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:optableAccount" style="position:relative">
//Below hidden field stores the id
<input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkid" type="hidden" value="001i0000008OJ9R" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkid">
<input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkold" type="hidden" value="Abbott Insurance" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkold">
<input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lktp" type="hidden" value="001" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lktp">
<input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspf" type="hidden" value="0" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspf">
<input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspfsub" type="hidden" value="0" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lspfsub">
<input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_mod" type="hidden" value="1" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_mod">
<span class="lookupInput"> // Below input stores the name
<input id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup" class="accClass" type="text" size="20" onchange="getElementByIdCS('leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkid').value='';getElementByIdCS('leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_mod').value='1';" name="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup" maxlength="255" style="opacity: 0.1; width: 250px;">
<script>
<a id="leadConversionPage:leadConversionForm:pBConvertLead:pbSectionLeadSection:pbsiAccountName:accountLookup_lkwgt" class="accClass" title="Account Name Lookup (New Window)" onclick="setLastMousePosition(event)" href="javascript:%20openLookup%28%27%2F_ui%2Fcommon%2Fdata%2FLookupPage%3Flkfm%3DleadConversionPage%253AleadConversionForm%26lknm%3DleadConversionPage%253AleadConversionForm%253ApBConvertLead%253ApbSectionLeadSection%253ApbsiAccountName%253AaccountLookup%26lktp%3D%27%20%2B%20getElementByIdCS%28%27leadConversionPage%3AleadConversionForm%3ApBConvertLead%3ApbSectionLeadSection%3ApbsiAccountName%3AaccountLookup_lktp%27%29.value%2C670%2C%271%27%2C%27%26lksrch%3D%27%20%2B%20escapeUTF%28getElementByIdCS%28%27leadConversionPage%3AleadConversionForm%3ApBConvertLead%3ApbSectionLeadSection%3ApbsiAccountName%3AaccountLookup%27%29.value.substring%280%2C%2080%29%29%29">
</span>
<select id="someList" class="accSelectandlookup" >
</div>
//下面隐藏的字段存储id
//下面输入存储名称
每当名称更改时,id也会更改。当名称更改时,我需要捕获id并将其添加到select中
查找的名称和id是accountLookup,要获取名称,我可以搜索以accountLookup结尾的所有输入。在我的表单中可以有多个查找,但我只需要此查找的名称和id,它的名称/id中包含accountLookup,并将其附加到select中
这是我在SO中一些伟大人物的帮助下完成的jquery。
我面临的问题是我没有得到id值。它是空白的
$('input[id*="accountLookup"]').change(function() {
var accid ='';
//Loop through all the textboxes and find the one with lkid
$.each(['up_lkid'], function(i,element) {
accid = getInputValue(element); // Get the value of the inputbox ending with lkid
alert('llllll' + accid);
});
var accname= $(this).val();
//Get the closest div and find for an elemnet which has class of accSelectLookup
var selects = $(this).closest('div').find('.accSelectandlookup') ;
//Check if the accid is already present in the selectoptions and if not then add
if (!selects.find('option[value="' + accid + '"]').length) {
selects.append('<option value="' + accid + '">Attach to Existing : ' + accname + '</option>');
}
});
function getInputValue(endWith) {
return $('input[id$="' + endWith + '"]').val();
}
});
$('input[id*=“accountLookup”]”)。更改(函数(){
var accid='';
//循环遍历所有文本框,找到具有lkid的文本框
$。每个(['up\u lkid'],函数(i,元素){
accid=getInputValue(元素);//获取以lkid结尾的inputbox的值
警报('llll'+accid);
});
var accname=$(this.val();
//获取最近的div并查找具有accSelectLookup类的elemnet
var-selects=$(this.closest('div').find('.accSelectandlookup');
//检查accid是否已存在于selectoptions中,如果没有,则添加
如果(!selects.find('option[value=“”+accid+“]]).length){
选择.append('附加到现有:'+accname+'');
}
});
函数getInputValue(endWith){
返回$('input[id$=“'+endWith+'“]')。val();
}
});
我尝试了类似$('input[id$=“accountLookup_lkid”]')。更改(function(){alert($(this.val());accid=$(this.val();alert({u lkid search'+accid);});。但是它根本不会进入方法中。你能创建一个JSFIDLE吗