简体   繁体   English

我在没有问题的页面上使用jquery和常规javascript,直到我添加了另一个功能

[英]I'm using jquery and regular javascript on a page with no probs until I added one more function

Here's what I'm doing. 这就是我在做什么。

I have a few images on a page with an HTML5 audio player underneath each one and a select menu with a list of sounds. 我在一个页面上有一些图像,每个图像下面都有一个HTML5音频播放器,还有一个带有声音列表的选择菜单。

When a sound is selected from the menu, it places that sound in the source of the audio player. 从菜单中选择声音后,它将声音放置在音频播放器的来源中。

What I want to do is change the image to an animated gif when the sound is played. 我要做的是在播放声音时将图像更改为动画gif。

The onchange works fine loading the sound into the player. onchange可以很好地将声音加载到播放器中。 But when I add the new onplay() call, none of the javascript works. 但是,当我添加新的onplay()调用时,所有的javascript都不起作用。

 function playPic(theid){ var leid = theid.replace('play',''); document.getElementById('leid'+pic).src="images/" + leid ".gif"; } $( function() { $( "#sortable" ).sortable(); $( "#sortable" ).disableSelection(); } ); $(document).ready(function() { $('#sortable').sortable(); //$('<br><br><div id=buttonDiv><button>Get Order of Elements</button></div>').appendTo('body'); //$('button').button().click(function() { $( "#sendgame" ).submit(function( event ) { var itemOrder = $('#sortable').sortable("toArray"); var fullOrder = ""; for (var i = 0; i < itemOrder.length; i++) { newi = i + 1; //alert("Position: " + i + " ID: " + itemOrder[i]); fullOrder += newi + " - " + itemOrder[i] + "<br>"; } //alert (fullOrder); document.forms["sendgame"].ordre.value = fullOrder; }) }); function recSon(lename, leson) { document.forms["sendgame"][lename].value = leson; } function loudSon(soundid, leplayer) { lesound = ""; if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { lesound = soundid + ".ogg"; } else { lesound = soundid + ".mp3"; } } 

The playPic function is what screws everything up. playPic函数可将所有内容搞砸。 I've tried it in different places in the code but always the same error : 我已经在代码中的不同地方尝试过,但是总是相同的错误:

Uncaught ReferenceError: recSon is not defined at HTMLSelectElement.onchange (jeuhockeynoir.php?lang=f:481) onchange @ jeuhockeynoir.php?lang=f:481 未捕获的ReferenceError:在HTMLSelectElement.onchange(jeuhockeynoir.php?lang = f:481)上未定义recSon onchange @ jeuhockeynoir.php?lang = f:481

you're missing a + sign: 您缺少一个+号:

document.getElementById('leid'+pic).src="images/" + leid ".gif";

should be 应该

document.getElementById('leid'+pic).src="images/" + leid + ".gif";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery函数递归-我迷路了 - jQuery Function Recursion - I'm lost on this one JavaScript功能无法正常工作,我正在使用Codeigniter - Javascript function is not working I'm using codeigniter 使用JavaScript或JQuery,如何确定将DOM元素添加到页面的时间? - Using JavaScript or JQuery how do I determine when a DOM element is added to the page? 在 blazor 中使用 javascript,直到我点击页面才工作 - using javascript in blazor, not working until i click page 即使我正在使用 $(window).on(&#39;load&#39;, function(),jQuery 也会在页面完成加载之前执行 - jQuery executes before page finishes loading even though I'm using $(window).on('load', function() 使用不同的参数调用javascript函数,具体取决于我所在的页面 - Calling javascript function with different parameters, depending on which page I'm on 将onclick事件添加到javascript中新创建的表格标题中,但是onclick函数被添加到页面上的所有内容中,而不仅仅是我想要的一个 - Adding onclick event to newly created table header in javascript, but the onclick function is added to all th's on the page, not just the one I want 为什么我无法使用jQuery将HTML动态添加到页面? - Why I'm not able to dynamically add the HTML to the page using jQuery? 我可以告诉我的 php 函数在“file_get_contents”使用 php 代码中的 javascript 加载页面之前不执行吗? - Can I tell my php function to not execute until the "file_get_contents" has loaded the page using javascript in php code? 当我用jquery按钮单击时,javascript函数将执行更多次 - javascript function execute more times when i click with jquery button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM