简体   繁体   English

使用jQuery获取列表中选定项目的值

[英]get values of selected items in list with jquery

i have one list in php page with follwoing script 我在follwoing脚本的php页面中有一个列表

<div id='demo' style="padding-left:20px">

<select name='lists[]' multiple='multiple' class='multiselect' >
<?php

$sql="select list_id,list_name from tbl_list";
$result=mysql_query($sql);
for($i=1;$i<=mysql_num_rows($result);$i++)
{
$row=mysql_fetch_array($result);
?>
<option  value='<?php echo $row['list_id']; ?>' title='<?php echo $row['list_name']; ?>'><?php echo $row['list_name']; ?></option>
 <?php
 }
 ?>           
  </select>
        </form>
      </div>

now after i select multiple rows in list box, i want to get the values of selected rows with jquery. 现在,我在列表框中选择多行之后,我想使用jQuery获取选定行的值。

Thanks 谢谢

$('select').val();

将以x,y,z的形式返回您选择的值

$('select').val();

to get the value of the select at that time 得到当时的选择价值

$('select').change(function(){
    alert($(this).val());
});

To get it every time it is changed. 要在每次更改时获取它。

Example for multiple selects on a page: http://jsfiddle.net/Mxtey/ 页面上的多个选择的示例: http : //jsfiddle.net/Mxtey/

Hope this helps 希望这可以帮助

try $("select").serialize(); 尝试$("select").serialize(); and it probably give you exactly what you want however there should be "form" first and after that you should use 它可能会给您确切想要的东西,但是应该首先使用“表单”,然后再使用

$("form").serialize();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM