javascript-events

jQuery dropdown select event

倾然丶 夕夏残阳落幕 提交于 2021-02-05 09:30:29
问题 Is there a specific event for when a user selects an item in a dropdown box? I am creating a fairly large form that uses multiple dropdown boxes. On load all but the first are disabled, as the user selects the first option the options in the second box change using AJAX and I want to remove the attribute disabled. $('#site_id').on('change', function(event) { $('#access_type_id').removeAttr('disabled'); }); The trouble I am having is that .change() seems to be fired when the options in a

Javascript: Add event listener to document opened in new window

南楼画角 提交于 2021-02-04 14:15:30
问题 Is there anything that prevents me from adding a event listener to the window that results from a window.open() call? I am trying to set a handler function to be triggered on a visibility change event on the new document, but this handler function is not being called. 回答1: There's nothing that prevents you from doing that ( as long as the window you are opening is in the same domain as the parent/opener window; Just imagine what malicious people could do if that weren't the case ). Once you

Javascript: Add event listener to document opened in new window

烂漫一生 提交于 2021-02-04 14:15:28
问题 Is there anything that prevents me from adding a event listener to the window that results from a window.open() call? I am trying to set a handler function to be triggered on a visibility change event on the new document, but this handler function is not being called. 回答1: There's nothing that prevents you from doing that ( as long as the window you are opening is in the same domain as the parent/opener window; Just imagine what malicious people could do if that weren't the case ). Once you

Add additional parameters to event function

牧云@^-^@ 提交于 2021-02-04 06:13:22
问题 I have an event, and I want to add additional parameters to the named function. I tried following 2 things: myDiv.addEventListener('click', evt.call(this, event, 'hello')); And myDiv.addEventListener('click', evt(event, 'hello')); And the problem with both of them, is they get called right away, and don't get called when you click myDiv , i.e. when it's supposed to get called. How can I add additional parameters to the named function event? JSFiddle console.clear(); var myDiv = document

Add additional parameters to event function

醉酒当歌 提交于 2021-02-04 06:13:15
问题 I have an event, and I want to add additional parameters to the named function. I tried following 2 things: myDiv.addEventListener('click', evt.call(this, event, 'hello')); And myDiv.addEventListener('click', evt(event, 'hello')); And the problem with both of them, is they get called right away, and don't get called when you click myDiv , i.e. when it's supposed to get called. How can I add additional parameters to the named function event? JSFiddle console.clear(); var myDiv = document

Add additional parameters to event function

让人想犯罪 __ 提交于 2021-02-04 06:11:52
问题 I have an event, and I want to add additional parameters to the named function. I tried following 2 things: myDiv.addEventListener('click', evt.call(this, event, 'hello')); And myDiv.addEventListener('click', evt(event, 'hello')); And the problem with both of them, is they get called right away, and don't get called when you click myDiv , i.e. when it's supposed to get called. How can I add additional parameters to the named function event? JSFiddle console.clear(); var myDiv = document

Add additional parameters to event function

♀尐吖头ヾ 提交于 2021-02-04 06:11:28
问题 I have an event, and I want to add additional parameters to the named function. I tried following 2 things: myDiv.addEventListener('click', evt.call(this, event, 'hello')); And myDiv.addEventListener('click', evt(event, 'hello')); And the problem with both of them, is they get called right away, and don't get called when you click myDiv , i.e. when it's supposed to get called. How can I add additional parameters to the named function event? JSFiddle console.clear(); var myDiv = document

Why doesn't event bubbling work in detached DOM elements?

北战南征 提交于 2021-01-27 05:12:08
问题 I have a parent <div> with one child <div> in memory - not attached to the current document. I want to trigger a CustomEvent on the child but listen to that event from the parent. Here is my code: var parent = document.createElement('div'); var child = document.createElement('div'); parent.appendChild(child); parent.addEventListener('boom', function(event) { console.log('parent listener', event); // <~ This never runs! }); var event = new CustomEvent('boom', { bubbles: true }); child

Why doesn't event bubbling work in detached DOM elements?

烈酒焚心 提交于 2021-01-27 05:11:07
问题 I have a parent <div> with one child <div> in memory - not attached to the current document. I want to trigger a CustomEvent on the child but listen to that event from the parent. Here is my code: var parent = document.createElement('div'); var child = document.createElement('div'); parent.appendChild(child); parent.addEventListener('boom', function(event) { console.log('parent listener', event); // <~ This never runs! }); var event = new CustomEvent('boom', { bubbles: true }); child

How to change onclick using javascript?

可紊 提交于 2020-12-08 07:14:09
问题 How to change onclick using javascript ? https://jsfiddle.net/749rt0m7/1/ I tried to use this code, but not work. How can i do ? <span onclick="test_fn('aaa,bbb')" id="xx">edit</span> <script> document.getElementById('xx').onclick = "test_fn(111,222)"; </script> 回答1: There are a couple things going on here. First of all test_fn() is not a function in your jsfiddle. You will need to define it in order for it to be called. Second of all you are setting the onclick attribute to be a string not a