当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How do i trigger a lightbox when certain text is selected using jQuery?

问题描述:

Ok so i have this

<select class="something">

<option value=''>

Select a Project

</option>

---

</option>

<option value="/projects/2">test</option>

<option value="/projects/3">test2</option>

<option value="/projects/4">test7</option>

<option value="/projects/5">test5</option>

When someone clicks the Select a Project how would popup a lightbox just for that and not if they select the others....Popping up the lightbox is not too hard its distinquishing from the other options that i dont understand

$(".something").change

this will get all but i only want "Select a Project"

网友答案:
$('.something').change(function() {
   if ($(this).val() == '') {
      // Your code here:
   }
});
网友答案:

Here's how I'd do it:

$(".something").bind("change", function(eventObj) {
    if($(":selected",this).text() === "Select a Project") {
        // open lightbox
    }
});

I like checking .val() in most cases, but if your value is an empty string...I feel iffy about it so I would check against the text of the selected option in this case.

分享给朋友:
您可能感兴趣的文章:
随机阅读: