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