javascript-events

using jQuery's delegated event on() within every turbolinks page:load

蓝咒 提交于 2020-01-02 21:54:34
问题 I had this code in my rails app: $(document).ready( function() { myCustomFunction("#link-selector"); } function myCustomFunction(linkCssSelector){ // some stuff... $(document).on('click', linkCssSelector, function(){ // ...some other stuff... }); } The click event handling is already delegated to the document , but now I have to add Turbolinks to my app. Then, I would take of the ready() function and do the following (based on my searches): $(document).on("ready page:load", function() {

jQuery replacement for onclick

别等时光非礼了梦想. 提交于 2020-01-02 18:16:12
问题 I've just recently discovered the power of jQuery. Just a quick question though. What is a replacement for onclick="DeleteSomething('THE ID NUMBER LOADED IN BY SERVER SIDE')" ? Is there even a way somehow to pass custom information such as an ID to a jquery onclick? Or do i have to stay with the old fashioned way? Thanks a lot! Adam 回答1: I usually use a rel="" for some extra data i might need attached to the button or whatnot. for example <input class="btnDelete" rel="34" value="Delete" />

How to display “selected radio button” after refresh?

…衆ロ難τιáo~ 提交于 2020-01-02 12:01:34
问题 After refresh the page, the user selected radio button is missing. How can i always display the user's "selected radio button" even I had refresh the page? <input name="radiobutton" type="radio" value="" id="all" checked /> radio with checked is not suitable, because it will always display the default radio button. Below is my code:- <form name="myfrm" id="myfrm" action="" method="post"> <input name="radiobutton" type="radio" value="" id="all" /> <label>All Languages</label> <input name=

How to display “selected radio button” after refresh?

谁说胖子不能爱 提交于 2020-01-02 12:01:32
问题 After refresh the page, the user selected radio button is missing. How can i always display the user's "selected radio button" even I had refresh the page? <input name="radiobutton" type="radio" value="" id="all" checked /> radio with checked is not suitable, because it will always display the default radio button. Below is my code:- <form name="myfrm" id="myfrm" action="" method="post"> <input name="radiobutton" type="radio" value="" id="all" /> <label>All Languages</label> <input name=

Problem with disabling submit buttons on form submit

和自甴很熟 提交于 2020-01-02 08:02:33
问题 Greetings I am using the jquery disable on submit plug-in but I have a problem. If I disable the submit buttons they dont get passed back to the server so I cant tell which button was pressed. Is this normal? Is there anything I can do about it? I really dont want to retool my website so I have to set a variable on form submission to tell which button was pressed. Any ideas ? 回答1: Here's a workaround I just found in a jQuery forum: <script type="text/javascript"> $(document).ready(function()

addEventListener click executed before clicked

爷,独闯天下 提交于 2020-01-02 07:25:12
问题 I want to pass over parameters in the click function. var albums = document.getElementsByClassName("album"); for(var i = 0; i<albums.length; i++){ document.getElementById(albums[i].id).addEventListener("click", goAlbum(albums[i].id), false); } however, the function "goAlbum" gets excecuted when it is created, and then the function won't excecute anymore. what am I doing wrong? 回答1: goAlbum was getting executed because you called the function. You weren't "creating" a function. What you

How to make $(document).ready() functions available globally?

六月ゝ 毕业季﹏ 提交于 2020-01-02 04:12:05
问题 I have an interesting question here that may sound pretty silly, but here goes. Using JQuery's ready function I have defined some functions like so: $(function(){ var function1 = function(data){ //do something } var function2 = function(data){ //do something else } }); For some reason, in order for IE to render what I am using correctly, it must be done in the $(document).ready() function. However, I need to trigger these functions once I have a dataset from the server-side. So I thought I

How to run a javascript function after a specific JS has loaded?

梦想的初衷 提交于 2020-01-02 03:52:05
问题 I have made a js function for including another javascript in my html. I need to make sure that the script I have loaded using the function is has completed processing and then only move further in my original script. function loadBackupScript(){ var script = document.createElement('script'); script.src = 'http://www.geoplugin.net/javascript.gp'; script.type = 'text/javascript'; var head = document.getElementsByTagName("head")[0]; head.appendChild(script); } I need to know that the script has

How do I prevent, stop, or kill Javascript function?

自闭症网瘾萝莉.ら 提交于 2020-01-02 02:52:06
问题 How do I prevent this Javascript function from executing. I have a js function that is causing a serious issue and I am not able to remove nor modify it source. I would like to know if it is possible to simply prevent, stop, or kill the function in order that it is not executed till I resolve the issue. So somewhere inside the page: <script type="text/javascript"><!-- problem_func(); //--></script> And all I want is to stop that function from execution placing a stopper inside the header or

How do I prevent, stop, or kill Javascript function?

吃可爱长大的小学妹 提交于 2020-01-02 02:52:05
问题 How do I prevent this Javascript function from executing. I have a js function that is causing a serious issue and I am not able to remove nor modify it source. I would like to know if it is possible to simply prevent, stop, or kill the function in order that it is not executed till I resolve the issue. So somewhere inside the page: <script type="text/javascript"><!-- problem_func(); //--></script> And all I want is to stop that function from execution placing a stopper inside the header or