"> "> " />

JQuery yordamida JSF komponentlarini qanday tanlash mumkin?

JQuery'ni PrimeFaces va JSF komponentlari bilan amalga oshirishga harakat qilaman, lekin u to'g'ri ishlamayapti. HTML teglar bilan bir xil ishni qilishga harakat qilsam, u to'g'ri ishlaydi.

JQuery bilan to'g'ri ishlaydigan HTML teglar kodi:

<input type="checkbox" id="check2">
 

bilan

$("#check2").change(function() {
    if ($("#check2").is(":checked")) {
        $("#p2").hide();
    } else {
        $("#p2").show();
    }
});

Here is the code bilan PrimeFaces/JSF which doesn't work properly bilan jQuery:


    

bilan

$("#rad").change(function() {
    if ($("#rad:checked").val() == "one") {
        $("#p2").hide();
    } else {
        $("#p2").show();
    }  
});
35

4 javoblar

You should realize that jQuery works with the HTML DOM tree in the client side. jQuery doesn't work directly on JSF components as you've written in the JSF source code, but jQuery works directly with the HTML DOM tree which is generated by those JSF components. You need to open the page in webbrowser and rightclick and then View Source. You'll see that JSF prepends the ID of the generated HTML input elements with the IDs of all parent NamingContainer components (such as , , etc) with : as default separator character. So for example


    
    ...

yaratilgan HTML sifatida tugaydi

<form id="foo" name="foo">
    <input type="checkbox" id="foo:bar" name="foo:bar" />
    ...

Buning o'rniga ushbu identifikatorni aniq elementlari bilan tanlashingiz kerak. : - bu faqat soxta kodni ifodalovchi CSS-identifikatorlarida maxsus belgi. JQuery'da CSS tanlovchilaridan foydalangan holda identifikatorda : elementli elementni tanlash uchun

ID kodida XXX kodi raqamini ifodalovchi autentifikatsiya qilingan j_idXXX qismini ko'rsangiz, unda majburiy kerak incremental raqam dinamik va daraxtdagi komponentning jismoniy holatiga qarab o'zgarishi mumkin.


Shu bilan bir qatorda, siz faqat sinf nomini ishlatishingiz mumkin:


HTML sifatida nihoyasiga yetadi

<input type="..." class="someClassName" />

Siz uni shunday qilib olishingiz mumkin

var $elements = $(".someClassName");

Bu yaxshi ajratish va qayta foydalanishga imkon beradi. Albatta, bunday elementlar noyob emas. Faqat nom, menyu, kontent va taglavha kabi asosiy tartib elementlari, albatta, noyobdir, lekin ular odatda NamingContainer da mavjud emas.


Yana bir muqobil sifatida, siz HTML DOM elementini o'zingizning vazifangizga topshirishingiz mumkin:


function someFunction(element) {
    var $element = $(element);
   //...
}

Shuningdek qarang:

72
qo'shib qo'ydi

Bundan tashqari, jQuery "Atribut o'z ichiga oladi Selector" (bu erda url http://api. jquery.com/attribute-contains-selector/ )

Misol uchun, agar sizda bo'lsa

  

va uning ob'ektida biror narsa qilishni xohlasangiz, uni tanlashingiz mumkin

jQuery('input[id*="quantity"]')

Agar siz uning qiymatini chop qilmoqchi bo'lsangiz, buni amalga oshirishingiz mumkin

alert(jQuery('input[id*="quantity"]').val());

Elementning haqiqiy html yorlig'ini bilish uchun har doim haqiqiy HTML elementiga (bu holatda spinner kirishga tarjima qilingan) firebug'ni yoki ya'ni ishlab chiquvchi vositalarini yoki manbani ko'rsata oladi ...

Doniyor.

5
qo'shib qo'ydi

enter image description here look this will help you when i select experience=Yes my dialoguebox which id is dlg3 is popup.and if value is No it will not open

3
qo'shib qo'ydi

If you're using RichFaces you can check rich:jQuery comonent. It allows you to specify server side id for jQuery component. For example, you have component with specified server id, then you can apply any jQuery related stuff to in next way: .

Qo'shimcha ma'lumot olish uchun, iltimos, faylini tekshiring .

Umid qilamanki yordam beradi.

1
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb