English 中文(简体)
• 如何对选择人的多个配对进行约束:
原标题:How to bind multiple pair of selector:event in jQuery ON method

http://api.jquery.com/on/“rel=“nofollow”>。 方法,但未能执行,请帮助我。

>Fiddle

基本上在此,我

HTML

<ul id="sortByRight" >
     <li id="1"><a href="javascript:void(0)">List</a></li>
     <li id="2"><a href="javascript:void(0)">Photo</a></li>
     <li id="3"><a href="javascript:void(0)">Map</a></li>
</ul>

<select name="sort" id="sort"  >
   <option value="1">Recommended</option>
   <option value="2">Price: low to high</option>
   <option value="3">Price: high to low </option>
   <option value="4">Newest</option>
</select>

jQuery code

$(document).on( change click ,  ul#sortByRight,select#sort , function() { 
               selectedOption = $( select#sort ).val();
               whatToShow = $(this).attr( id );
               alert( selectedOption: +selectedOption+ whatToShow: +whatToShow);
              }
);

现在,我已面临问题/问题。

  • can we bind one event with one selector i.e. above function should be called
    EITHER on change of selectbox OR on click of ul.

  • 如何在<条码>方法上设定<条码>数据。 我尝试如下:

    $(document).on( change click , ul#sortByRight,select#sort ,
    { selectedOption : $( select#sort ).val(), whatToShow : $(this).attr( id ) } ,
    function(){console.log( selectedOption: +selectedOption+ whatToShow: +whatToShow);}
    );

    但没有界定<条码>选择使用错误。

  • 我们可以撰写如下内容:$ (this, li);,因为我需要id of li,而不是选择的

  • if there is any other optimized solution ( using function like live or bind ), then please tell me.

感谢A Lot。

问题回答

我不明白你实际上想要做些什么,但一件事没有意义。 当选定盒子变换时,你要寄出利比里亚的身份证。 哪一个条件? 最后一个被点击的LLL? 你们需要储存活性电离层状态,这样,如果选择箱子发生变化,你就可以在贾汉斯的请求中寄出。

也许像这样:

$( select#sort ).change(function() {
    processAjax();
});


$( ul#sortByRight > li > a ).click(function() {
    $(this).closest( ul ).find( li ).removeClass( active );
    $(this).closest( li ).addClass( active );

    processAjax();
});

function processAjax() {
    selectedOption = $( select#sort ).val();
    whatToShow = $( ul#sortByRight ).find( .active ).attr( id );
    alert( selectedOption:  + selectedOption +  whatToShow:  + whatToShow);
}

或检查jsFiddle





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...