JQuery移动端多选框

4

我查看了所有关于jquery mobile多选的主题,但仍然无法弄清楚我的代码有什么问题。

http://jsfiddle.net/HMWYu/

<!DOCTYPE html> <html>
<head>  <title>Registration</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
    <div data-role="page" id="home">
        <header data-role="header">
        <h1>Register</h1>
   </header>
         <div data-role="content">
                       <div data-role="fieldcontain">
                <label for="Services" class="ui-hidden-accessible ">
                    Services:</label>
                <select name="Services" id="Services"  multiple="multiple" size="4">
                    <option >Hotel</option>
                    <option >Transport</option>
                    <option >Others</option>
                </select>
            </div>
        </div>
            </div>
</body>
</html>

任何帮助都将不胜感激。
1个回答

13

使用JQM自定义选择菜单进行多选。 http://jquerymobile.com/demos/1.0.1/docs/forms/selects/custom.html 首先,在您的选择菜单中添加data-native-menu="false"。 然后确保您的选项具有值。 我添加了一个选项作为占位符,取代标签。 这是我的示例:

<!DOCTYPE html> 
<html>
<head>
    <title>Registration</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<div data-role="page" id="home">
   <header data-role="header">
        <h1>Register</h1>
   </header>
   <div data-role="content">
       <div data-role="fieldcontain">
           <label for="Services"  class="ui-hidden-accessible " >
               Country:
           </label>
           <select name="Services" id="Services" data-native-menu="false" data-mini="true" multiple="multiple" size="4">
               <option>Country</option>
               <option value="hotel">Hotel</option>
               <option value="transport">Transport</option>
               <option value="others">Others</option>
           </select>
       </div>
    </div>
</div>
</body>
</html>

1
你如何确保所有选定的选项都被发送到服务器?在我的情况下,只有最后一个选定的选项被发送。 - Pascal Klein
所有的值都已经发送给我了。你确定你是在使用req.getParameterValues()而不是仅仅使用req.getParameter()吗? - Joe M

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接