简体   繁体   English

在Joomla 2.5中使用jQuery将onChange属性添加到选择中

[英]add onChange attribute to a select using jQuery in Joomla 2.5

I need to add the onChange attribute to a drop down list using jQuery in Joomla. 我需要在Joomla中使用jQuery将onChange属性添加到下拉列表中。 I have tried the following way: 我尝试了以下方法:

jQuery(document).ready(function($) {
    alert("hello world");
    jQuery("#jform_fkcategory").attr('onChange', 'foo();');
});

jQuery is working fine as the alert is popping up. 警报弹出时,jQuery工作正常。 I am unable to add the attribute only. 我无法仅添加属性。 Please help me! 请帮我!

This is my form field: 这是我的表单字段:

    <field
        name="fkcategory"
        type="category"
        class="inputbox"
        label="Category"
        description=""
        required="true">
        <option value="">Select Category</option>
    </field>

This is what i've in layout. 这就是我的布局。

<select id="jform_fkcategory" name="jform[fkcategory]" class="inputbox required">

You're almost there. 你快到了。 Alter your JavaScript like so: 像这样更改您的JavaScript:

(function($) {

    function foo() {
        $.ajax({
            // place AJAX request params here
        });
    }

    $(document).on('change', '#jform_fkcategory', foo);

})(jQuery);

Enclose any code to execute when the onchange event is fired inside the foo function. 封装在foo函数中触发onchange事件时要执行的所有代码。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM