[英]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.