Useful knowledge of Javascript - 1

linkaiyi
Follow

load js file with jquery

jQuery.getScript()

Prevent right click menu in browsers

<body oncontextmenu="return false;">

You can disable context menu on any element you want:

$('selector').contextmenu(function() {
    return false;
});

To disable context menu on the page completely (thanks to Ismail), use the following:

$(document).contextmenu(function() {
    return false;
});

add option to select2 dynamically

selector_lesson.empty().trigger('change');
    var newOption = new Option('--Alle--', '-1', false, false);
    selector_lesson.append(newOption).trigger("change");
    for (var i = 0; i < data.length; i++){
        newOption = new Option(data[i].text, data[i].id, false, false);
    selector_lesson.append(newOption).trigger("change");
}

get select value. It works for both select and optgroup

$('select[name="lesson"]').val();

dynamically get select option change event

selector_category.on('change', function() {})

check the checkbox status

For dropdown options you probably want something like this:

var conceptName = $('#aioConceptName').find(":selected").text();

The reason val() doesn’t do the trick is because clicking an option doesn’t change the value of the dropdown—it just adds the :selected property to the selected option which is a child of the dropdown.

Object has 0 attachments

Was this article helpful?

This article is viewed 25 times!

Recent Viewed Articles

0 Comments

Leave a Comment

Support