xajax如何给select增加值


<?php
require_once("xajax/xajax_core/xajax.inc.php");
function testForm($formData)
{
    switch ($formData) {
        case 1:
                $objResponse = new xajaxResponse();
                $objResponse->alert("china");
                //这如何写
                return $objResponse;
        break;
        case 2:
                $objResponse = new xajaxResponse();
                $objResponse->alert("USA");
                return $objResponse;
        break;
    }
}
$xajax = new xajax();
//$xajax->setFlag("debug", true);
$xajax->registerFunction("testForm");
$xajax->processRequest();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>PHP+XAJAX级联菜单</title>
<?php $xajax->printJavascript("xajax") ?>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
 <select name="gaojia" id="gaojia" onchange="xajax_testForm(document.getElementById('gaojia').value); return false;">
  <option value="1">中国</option>
  <option value="2">美国</option>
  <option value="请选择">请选择</option>
 </select>
 <select name="cheng">
 </select>
</form>
</body>
</html>

  可以看看下面的代码

  <select id="ddlResourceType" onchange="getvalue(this)">

  </select>

  动态删除select中的所有options:

    document.getElementById("ddlResourceType").options.length=0;

  动态删除select中的某一项option:

    document.getElementById("ddlResourceType").options.remove(indx); 

  动态添加select中的项option:

    document.getElementById("ddlResourceType").options.add(new Option(text,value));

  上面在IE和FireFox都能测试成功,希望以后你可以用上。

  其实用标准的DOM操作也可以,就是document.createElement,appendChild,removeChild之类的。

  取值方面

  function getvalue(obj)
  {
     var m=obj.options[obj.selectedIndex].value
     alert(m);//获取value
     var n=obj.options[obj.selectedIndex].text
     alert(n);//获取文本
  }


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3