开发者

JSF wont allow to generate html tags through jquery & javascript?

I'm using jsf 2.0 ,richfaces 4.0 to implement my application. I used some times jQuery & javascript function for show & hide. But when I generate tags in xhtml page then it wont allow me.

Foe e.g: I want to append image for rich:autocomplete component of jsf for each serach result. So I write the code like this:

<script type="text/javascript">
function addPhotoPage(){
    var allDiv=$('#frmContent\\:txtPatientSearchItems').find('div');
    $.each(allDiv,function(cnt,data){
   $(this).append("<img src="./resources/images/photo.png">");
    });
}
</script>

this code written in xhtml page.

JSF strictly checks all the tags so it wont allow me to append img tag to r开发者_开发技巧esult of search.

Thank you.


The first thing you have to know is that Richfaces is provided with both Prototype and jQuery. Thus, $ does not refer to jQuery, but to Prototype. You should use directly jQuery instead of $ in your code.

The second thing you should consider is to use ' instead of " for the definition of your <img> attribute.

Finally, you can simplify your jQuery code.

So try to change your code to:

function addPhotoPage() {
    jQuery("#frmContent\\:txtPatientSearchItems").find("div").append("<img src='./resources/images/photo.png'>"));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜