简体   繁体   English

我如何使用 <select onChange>更改页面内容的元素?

[英]How Do I Use the <select onChange> Element to Change Content of a Page?

I'm wondering if anyone has had any experience using the the following HTML element? 我想知道是否有人使用以下HTML元素有任何经验?

<select onChange="function()"></select>

I'm looking to add some functionality to a sports fixture page on a site I am currently building. 我正在为当前正在构建的网站上的运动器材页面添加一些功能。 I want the user to be able to select a round and within the containing area content appears depending on which round is selected from the option element. 我希望用户能够选择一个回合,并且根据从选项元素中选择了哪个回合,将在包含区域内显示内容。

I have an example of what I am exactly trying to achieve here . 我有一个例子,说明我在这里想要实现的目标 I have also had a look at the W3 Schools example. 我也看过W3 Schools的例子。 However due to my beginner level of knowledge and experience using JavaScript I am having some difficulties achieving what I'm looking for. 但是,由于我的初学者知识和使用JavaScript的经验,我在实现所需内容方面遇到了一些困难。

I have been searching solidly online and through the code of the AFL Fixture page but I just can't seem to find anything on how this can be achieved. 我一直在网上搜索并通过AFL固定装置页面的代码进行可靠搜索,但是我似乎找不到关于如何实现此目标的任何信息。

Any advice on how I can get this done would be greatly appreciated. 我将如何完成这项工作的任何建议将不胜感激。

Thanking you in advance 预先谢谢你

Stu : ) 斯图:)

Do you have any restrictions on any libraries you can use? 您对可以使用的任何库有任何限制吗? Using jQuery you can do it quite simply by using 使用jQuery,您可以通过使用相当简单的方法

$('select').change(function(){ /* CODE HERE */ });

Check out this fiddle here: http://jsfiddle.net/pavkr/0k3ngfek/ 在这里查看这个小提琴: http : //jsfiddle.net/pavkr/0k3ngfek/

EDIT: Updated fiddle with dataset: http://jsfiddle.net/pavkr/0k3ngfek/1/ 编辑:用数据集更新了提琴: http : //jsfiddle.net/pavkr/0k3ngfek/1/

What you wanna use is Ajax . 您要使用的是Ajax

When onChange() is called, get the selected value from the function, and get the relative HTML content using $.ajax . 调用onChange() ,从函数中获取选定的值,并使用$.ajax获取相对HTML内容。

Then after the ajax call is completed, update the content using jqXHR.done() method. 然后,在ajax调用完成之后,使用jqXHR.done()方法更新内容。

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

相关问题 形式 <select>元素,如何使用onchange事件处理程序直接链接到所选选项? - In a form <select> element, how do I use the onchange event handler to link directly to the chosen option? JavaScript 如何在 onchange 事件和 select 元素中使用“this” - JavaScript How to use “this” with onchange event and select element 如何在“onchange”功能中更改“onchange”操作 - How do I change my "onchange" action in my "onchange" function 如何使用 onClick 和 onChange 使用 jquery 更改元素 select 选项 - How to change element select option with onClick and onChange using jquery 如何添加OnChange事件以选择使用custom-form-elements.js设置样式的元素? - How do I add OnChange event to select element that is styled with custom-form-elements.js? 更改a中的项目 <select>换另一个<select>元件 - Change items in a <select> onchange of another <select> element 如何以编程方式更改选择以激活其onchange行为? - How do I programmatically change a select so that it fires its onchange behavior? 我们如何在选择中使用Laravel Jquery onchange元素? - how we can use in Laravel Jquery onchange element in select? 如何隐藏 <select>通过onchange元素 - how to hide <select> element by onchange Textarea内容随javascript中的选择选项onchange而变化 - Textarea content change with select option onchange in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM