基于ID的绑定事件与JSF和jQuery

我遇到了JQuery和JSF / Richfaces的问题。 我在表单组件中有一个inputText组件。

  

我有以下jQuery代码:

 MySite.supplier= function() { // Only attach event listener if the element exists on page if ( jQuery('#myInputField') ) { jQuery('#myInputField').bind('paste', MySite.common.handleMousePaste.bind(this)); } }; MySite.common.handleMousePaste = function(event) { // Need to put a tiny delay in so the element has time to get the pasted n content. setTimeout(function() { jQuery("#" + event.target.id).keyup(); }, 10); }; 

问题是我的inputField呈现方式。 它将表单名称添加到其中,如下所示:

 myForm:myInputField 

所以我当前的jQuery代码将找不到要绑定的ID。

我没有用完整的表单名称jQuery(’#myForm \\:myInputField’)引用它的原因是因为我在整个站点的多个位置都有一个名为’myInputField’的字段(每页一次)

有没有任何解决方案可以在’MySite.supplier’方法中正确绑定到ID,以及在我有event.target.id的’MySite.supplier’方法中?

谢谢

JSF中命名容器的精彩之处。 当我玩这种东西时,我使用了jQuery的endsWith选择器(以下代码中的’$ =’)。

 jQuery('input[id$="myInputField"]') 

http://api.jquery.com/attribute-ends-with-selector/

你可以在文本框中分配一个类,然后只需使用类选择器来绑定粘贴事件吗?

   if ( jQuery('.bindPaste') ) { jQuery('.bindPaste').bind('paste', MySite.common.handleMousePaste.bind(this)); } 

关于jsfiddle的简单示例。

你有没有尝试过settig prependId为false。

form id =“myForm”prependId =“false”