簡體   English   中英

在控件組中觸發.click()事件

[英]Fire .click() event in controlgroup

嘗試為我的對照組觸發.click()事件。

編碼的HTML:

<div data-role="content" class="ui-content" role="main">
            <div id="gradegeoradio" data-role="fieldcontain">
                <fieldset data-role="controlgroup" data-type="horizontal">
                    <legend>
                    </legend>
                    <input id="grade" name="choose" value="Grade" type="radio"/>
                    <label for="grade">
                        Grade
                    </label>
                    <input id="geometry" name="choose" value="Geometry" type="radio"/>
                    <label for="geometry">
                        Geometry
                    </label>
                </fieldset>
            </div>...

DOM中的HTML:

<div class="ui-content" role="main" data-role="content"> <div id="gradegeoradio" class="ui-field-contain ui-body ui-br" data-role="fieldcontain"> <fieldset class="ui-corner-all ui-controlgroup ui-controlgroup-horizontal" data-type="horizontal" data-role="controlgroup"><div class="ui-controlgroup-label" role="heading"> </div> <div class="ui-controlgroup-controls"> <div class="ui-radio"> </div> <div class="ui-radio"><input id="geometry" type="radio" value="Geometry" name="choose"> </input><label class="ui-btn ui-corner-right ui-controlgroup-last ui-radio-on ui-btn-active ui-btn-up-c" for="geometry" data-corners="true" data-shadow="false" data-iconshadow="true" data-wrapperels="span" data-theme="c"> <span class="ui-btn-inner ui-corner-right ui-controlgroup-last"> <span class="ui-btn-text">

                        Geometry

</span></span></label></div></div></fieldset></div>

jQuery嘗試觸發事件:

$("#geometry").click();

事件監聽器:

$("#geometry, #grade").click(function(){do stuff after click}

我對所有這些都是新手,任何幫助將不勝感激。 抱歉,DOM中的HTML都是群集的,我復制並粘貼了它,但我不知道如何格式化它。

只是為了總結評論中給出的答案。

您需要先具有綁定,然后再觸發。 所以:

$("#geometry, #grade").click(function(){do stuff after click}

必須在之前

$('#geometry').click();

示例: http//jsfiddle.net/X2ExM/1/

如果您嘗試將事件綁定到幾何單選按鈕,而我認為這是您嘗試執行的操作,則可以使用類似以下內容的方法

$('#geometry, #grade').bind('click', function() {
    //do some thing
});
$('#geometry, #grade').trigger('click');

采用

   bind and trigger...

使用這個,這是工作

     $('#gradegeoradio').bind('click', function() {
      alert("hello to all");
     });

     $('#gradegeoradio').trigger('click');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM