I have created a fiddle with a really slimmed down version of my code. Even with the slim version I cannot seem to get my JQuery to work in either Safari or Chrome? Works fine on Firefox..
Take a look here: http://jsfiddle.net/7wAja/
Am I doing something wrong with jQuery(document).ready(function ($) {});
I can't figure out why even the click/alert won't work either that is I assumed it was that line?
Any help would be greatly appreciated, Im still a newb when it comes to jQuery or Javascript.
EDIT: My goal is to append the options value to the url, with that said this is what I have but neither this or the fiddle are working for me in chrome or safari and Im not sure if it is something I am doing wrong:
jQuery(document).ready(function($) {
$("#landing-select option").click(function(){
window.location.search = $(this).val();
});
});
not sure what you're trying to accomplish, but the option-element doesn't trigger a click event. the following works (mousedown on the select-element)
jQuery(document).ready(function ($) {
$('#landing-select').mousedown(function () {
alert('event triggered');
});
});
您需要添加多个选项以选择触发选项点击事件:
<select id="landing-select" class="select" name="items" multiple="multiple">
Instead of monitoring for clicks, why not just make a .change()
event?
jQuery(document).ready(function ($) {
$('#landing-select').change(function () {
alert($('#landing-select').val());
});
});
If you really have an event that you only want to fire on specific options, you could always do this:
jQuery(document).ready(function ($) {
$('#landing-select').change(function () {
if($('#landing-select').val() == "Option 1"){
alert("Option 1 specific stuff.");
}
});
});
And an update for your edit:
jQuery(document).ready(function($) {
$('#landing-select').change(function () {
window.location.search = $('#landing-select').val();
});
});
The simpilest way I have found is doing it like this
jQuery(document).ready(function ($) {
$('#landing-select').change(function () {
alert($(this).val());
});
});
If you want to append this to the URL, you could do the following
jQuery(document).ready(function ($) {
$('#landing-select').change(function () {
url = window.location.href;
url += '?'+$(this).val();
window.location.href = url;
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.