简体   繁体   English

我正在尝试从 <select>列到顶部,但是我的代码似乎不起作用

[英]I'm trying to move one element from a <select> list to the top, but my code doesn't seem to work

I have this page , and there is a <select> drop-down list next to 我有此页面 ,并且旁边有一个<select>下拉列表。
"Billing State (non-US scroll to bottom)" “帐单状态(非美国滚动到底部)”

I want to use Javascript to put the last item of that list (My state is not listed) to the top of the list. 我想使用Javascript将列表的最后一项(我的状态未列出)放在列表​​的顶部。

So far I tried this code: 到目前为止,我尝试了以下代码:

<script>
$(document).ready(function () {
$("select[name=billing_state]").find('option[value="_NOTLISTED_"]').prependTo($("select[name=billing_state]"));
});
</script>

I don't know why, it works on http://jsfiddle.net/4kHuA/21/ , but it doesn't work when I modify the html page and test it on the browser. 我不知道为什么,它可以在http://jsfiddle.net/4kHuA/21/上运行 ,但是当我修改html页面并在浏览器上对其进行测试时,它不起作用。

I'm not very experienced with Javascript, so maybe I did something really dumb. 我对Javascript不太了解,所以也许我做了一些愚蠢的事情。

Please make sure jquery.js which you refer to as $ has loaded before you call it in your script. 在脚本中调用jquery.js之前,请确保已将其称为$。 As @Sergio wrote, placing it before </body> tag may help a lot. 正如@Sergio所写,将其放在</body>标记之前可能会有很大帮助。

暂无
暂无

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

相关问题 当我尝试移动跨度时,appendChild不起作用 - appendChild doesn't work when I'm trying to move span 我试图将我的标签附加到我的li标签上,但它似乎不起作用? - I'm trying to append my a tag to my li tag but it doesn't seem to be working? 我试图在构造器中每秒调用一次方法15秒,但setInterval似乎不起作用 - I'm trying to call a method in a constructer every second for 15 seconds but setInterval doesn't seem to work 尝试使用错误消息验证我的表单似乎不起作用 - Trying to validate my form with error messages, doesn't seem to work 我正在尝试在JS中编写一个简单的异步代码,但它似乎不起作用 - I am trying to write a simple asynchronous code in JS, but it doesn't seem to work 我正在尝试使用nameInput的值更新div元素,我的代码对吗? - I'm trying to update my div element with the value of my nameInput, isn't my code right? 正则表达式在我的代码中似乎无法正常工作 - Regex doesn't seem to work properly in my code 我想先使用jquery加载后台,但我的代码似乎不起作用 - I want to load the background first using jquery but my code doesn't seem to work 我正在尝试为我的机器人在 discord.js 中创建一个自动角色 function 但它不起作用 - I'm trying to make an autorole function in discord.js for my bot but it doesn't work 我已经尝试过,但是我的程序似乎不起作用 - I have tried but my program doesn't seem to work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM