如何动态填充 facebook 中的下拉框?

发布于 2024-10-09 23:23:59 字数 265 浏览 0 评论 0原文

我这里有一个问题:我想根据另一个下拉框的选择动态填充一个下拉框!

在主下拉框中,我有一个 onchange= some_JS_function() ,它从我的 sql 服务器获取数据。如果我想要完整的下拉 html 代码并使用 setInnerXHTML() 放置它,那么从我的服务器接收到的部分代码将在新的下拉框中删除。除此之外其他一切都好!

我尝试将选项放入并放在适当的位置。然而,这根本不起作用。

有人可以帮我吗?

谢谢

- 阿山

I have a problem here : I want to dynamically populate a drop down box based on the selection of another drop down box !

in the main drop down box, I have an onchange= some_JS_function() that gets the data from my sql server. if I want to have the whole drop down html code and put it using setInnerXHTML(), then the part of the code received from my server is removed in the new drop down box. apart from that everything else is ok !

i tried to just have the options come in and put them at the appropriate places. however, this is not working at all.

can anyone please help me ?

thanks

-
ahsan

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

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

发布评论

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

评论(2

浴红衣 2024-10-16 23:23:59

我相信这就是您所需要的:

http: //remysharp.com/2007/01/20/auto-populate-select-boxes-using-jquery-ajax/

或者如果你只想用 JS 来完成:

<html>

<head>
    <title></title>
</head>

<body>
<script type="text/javascript">
    <!--
    function ReplaceContentInContainer(id) {
    var content;
    switch(id)
    {
        case "1":
        content = '<option>4</option><option>5</option><option>6</option>';
        break;

        case "2":
        content = '<option>7</option><option>8</option><option>9</option>';
        break;

        case "3":
        content = '<option>10</option><option>11</option><option>12</option>';
        break;

        default:
        content = '<option>1</option><option>2</option><option>3</option>';
    }
    document.getElementById("second").innerHTML = content;
    }
    //-->
</script>

<select name="test" id="test" onChange="ReplaceContentInContainer(this.options[this.selectedIndex].value)">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

<select name="second" id="second"></select>

</body>

</html>

I believe this is what you need:

http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/

Or if you want to do it with JS only:

<html>

<head>
    <title></title>
</head>

<body>
<script type="text/javascript">
    <!--
    function ReplaceContentInContainer(id) {
    var content;
    switch(id)
    {
        case "1":
        content = '<option>4</option><option>5</option><option>6</option>';
        break;

        case "2":
        content = '<option>7</option><option>8</option><option>9</option>';
        break;

        case "3":
        content = '<option>10</option><option>11</option><option>12</option>';
        break;

        default:
        content = '<option>1</option><option>2</option><option>3</option>';
    }
    document.getElementById("second").innerHTML = content;
    }
    //-->
</script>

<select name="test" id="test" onChange="ReplaceContentInContainer(this.options[this.selectedIndex].value)">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

<select name="second" id="second"></select>

</body>

</html>
花开半夏魅人心 2024-10-16 23:23:59

我相信这就是我所需要的: FBJS...OnClick 未通过。 DHTML/setInnerXHtml 问题

感谢您的帮助:)

I believe this is what I need : FBJS...OnClick not being passed. DHTML/setInnerXHtml problem

thanks for helping :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文