Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

jquery select change event on the same option

Here is my simple code:

$(".test").change(function(){
    alert("user clicked");
});

<select class="test">
    <option value="1">test1</option>
    <option value="2">test2</option>
</select>

It's all simple and working, but I want to get that function called not only when user changes option, but when he clicks on the same option that is already selected, I've tried click event but it gets fired up before user even clicka on any option, what could I do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

doesn't work in chrome.

$(".test option").click(function(e){
    console.log('click');
});

updated your fiddle.

put the click on the option

EDIT: looks like it isn't possible without a bunch of work like using click on the select and comparing the location it was clicked or something hokey like that.

I am not sure what the end goal is, but the click on the select might work if you can do the processing one extra time when they initially click into it.

another article on it:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...