首页 新闻 会员 周边

关于<select>的onchange()事件

0
悬赏园豆:10 [已解决问题] 解决于 2013-04-08 15:48

定义的select如下:

<td><select id ="selModel" onchange="javascript:SelectModelChange();" style ="width:160px;">
                         <option value="Citizen_Policeman02.Xpc" title="../model/Citizen_Policeman.png">警察</option>
                                <option value="Citizen_Female01.Xpc" title="../model/Citizen_Female.ico">市民</option>
                                <option value="Car.xpc" title="../model/Car.png">汽车</option>
                                <option value="Airplane.xpc" title="../model/Airplane.png">飞机</option>
                                <option value="Ship.fpc" title="../model/Ship.png">轮船</option>
                                <option value="" title ="../model/More.png" onclick ="javascript:SelectMoreModel();">更多...</option>
                         </select>
                     </td>

在 <script>中写的方法:

function SelectMoreModel() {
           
            var sel = document.getElementById('selModel');
            var value = showModalDialog("ModelList.aspx?rand=" + GetRandom(), "", "dialogWidth:250px; dialogHeight:500px; status:0; scroll:0;");
            alert(value);
            if (value != null) {
                var opt = document.createElement('option');
                opt.setAttribute('value', value);
                opt.innerText = value;
                opt.selected = true;
                sel.appendChild(opt);
            }
            document.getElementById("ScaleFactor").value = "0.2";
            document.getElementById("Height").value = "12";
            document.getElementById("Speed").value = "10";
            document.getElementById("TurnSpeed").value = "90";
        }

我想在点击“更多...”选项的时候跳转到

ModelList.aspx页面,选择一个模型,然后返回一个值给value,这个值就是新增<option>的值,但是运行时不起作用。
pengjw的主页 pengjw | 初学一级 | 园豆:3
提问于:2013-04-02 14:58
< >
分享
最佳答案
0

function SelectMoreModel() {
           
    var sel = document.getElementById('selModel');
    //此处修改
    var value = showModalDialog("ModelList.aspx?rand=" + GetRandom(), window, "dialogWidth:250px; dialogHeight:500px; status:0; scroll:0;");
    document.getElementById("ScaleFactor").value = "0.2";
    document.getElementById("Height").value = "12";
    document.getElementById("Speed").value = "10";
    document.getElementById("TurnSpeed").value = "90";
}

//
function Picker(url) {
    //取得传递进来的参数 window
    var parentWin =window.dialogArguments;
    var sel = parentWin.document.getElementById('selModel');
    var opt = parentWin.document.createElement('option');
    opt.setAttribute('value', value);
    opt.innerText = value;
    opt.selected = true;
    sel.appendChild(opt);
    window.close();
}

收获园豆:2
lixiangqian | 菜鸟二级 |园豆:206 | 2013-04-02 16:51
其他回答(3)
0
showModalDialog 这个是什么 能收到返回值?
收获园豆:1
丫的 | 园豆:1575 (小虾三级) | 2013-04-02 15:06

这是跳到另一个页面,ModelList.aspx,代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>模型列表</title>
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        function Picker(url) {
            window.returnValue = url;
            window.close();
        } 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="width: 100%; height: 500px; overflow-y: auto;">
        <asp:DataList ID="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" >
            <ItemTemplate>
                <table>
                    <tr>
                        <td align="center" valign="middle">
                            <a href="#">
                                <img src="<%#Eval("ImageUrl") %>" style="width: 48px; height: 48px; border: 0;" onclick="Picker('<%#Eval("FileName") %>');" />
                            </a>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>
支持(0) 反对(0) pengjw | 园豆:3 (初学一级) | 2013-04-02 15:10
0
option 没有 onclick 事件
你可以在 SelectModelChange 方法里调用SelectMoreModel
收获园豆:2
geass.. | 园豆:1821 (小虾三级) | 2013-04-02 15:07

哈哈,这思路好,我试试。

支持(0) 反对(0) pengjw | 园豆:3 (初学一级) | 2013-04-02 15:10

额,不太对,这样我选择“更多...”选项时达不到效果。

支持(0) 反对(0) pengjw | 园豆:3 (初学一级) | 2013-04-02 15:12

@pengjw: 

SelectModelChange 里判断一个 下拉框的值,如果为空就执行 SelectMoreModel
支持(0) 反对(0) geass.. | 园豆:1821 (小虾三级) | 2013-04-02 15:31
0

建议少用服务端控件,耗用系统资源大。 我的思路:

点' 更多 ..  ' 弹出 层(记录更多的选择项 的 .HTML) 选完后点确定 记录cookie值 ,在 调用页 调用COOKIE 动态添加<option>,弹出层个人感觉更美观, 引用  即可

收获园豆:5
月下花弄影 | 园豆:312 (菜鸟二级) | 2013-04-02 15:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册