如何使

发布于 2024-09-24 14:06:52 字数 159 浏览 0 评论 0原文

我想做的选项是<选择>通过程序(JS)显示或隐藏,可以吗?

就像StackOverFlow首页中有趣的标签一样,当你输入一些单词时,下拉列表会展开并给你建议。

ps.我知道StackOverFlow在这种情况下没有使用select,无论如何只是作为一个例子。

I want to make the options of < select > show or hide by program(JS),is it possible?

It is just like the interesting tags in the front page of StackOverFlow, when you type in some words, the drop list will expand and give you suggestions.

ps.I know StackOverFlow didn't use select in this case, anyway just take it as an example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢好甜 2024-10-01 14:06:52

您可以从 selectoptions 集合中添加或删除项目。

以下是删除一项并添加另一项的示例:

<html>
<head>
<title></title>
<script type="text/javascript">

function init() {
  // get a reference to the element
  var sel = document.getElementById('sel');
  // remove an option
  sel.options[2] = null;
  // create a new option and add to the select
  var opt = document.createElement('option');
  opt.value = '5';
  opt.text = 'five';
  sel.options.add(opt);
}

</script>
</head>
<body onload="init();">
<form>

<select id="sel">
  <option value="0">zero</option>
  <option value="1">one</option>
  <option value="2">two</option>
  <option value="3">three</option>
  <option value="4">four</option>
</select>

</form>
</body>
</html>

You add or remove items from the options collection of the select.

Here is an example that removes one item and adds another:

<html>
<head>
<title></title>
<script type="text/javascript">

function init() {
  // get a reference to the element
  var sel = document.getElementById('sel');
  // remove an option
  sel.options[2] = null;
  // create a new option and add to the select
  var opt = document.createElement('option');
  opt.value = '5';
  opt.text = 'five';
  sel.options.add(opt);
}

</script>
</head>
<body onload="init();">
<form>

<select id="sel">
  <option value="0">zero</option>
  <option value="1">one</option>
  <option value="2">two</option>
  <option value="3">three</option>
  <option value="4">four</option>
</select>

</form>
</body>
</html>
策马西风 2024-10-01 14:06:52
function getCatListdef(sel)
{
    var index = ajax.length;
    ajax[index] = new sack();
     ajax[index].requestFile = 'data.php?cat_code='+sel;
     ajax[index].onCompletion = function(){ createCities(index) };  
    ajax[index].runAJAX();    
}
function getCatListdef(sel)
{
    var index = ajax.length;
    ajax[index] = new sack();
     ajax[index].requestFile = 'data.php?cat_code='+sel;
     ajax[index].onCompletion = function(){ createCities(index) };  
    ajax[index].runAJAX();    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文