在 onchange 上调用 2 个 JS 函数,并且都返回一些值
Call 2 JS functions on onchange and both returns some value
我想在onchange事件上调用两个JS函数,两个函数都返回一些值。它没有给我第二个函数输出:
我的PHP代码:
<select name="lstTypex" id="lstTypex" onchange="javascript:showCondition(this.value);showInputType(this.value);">
In options some values
</select>
<span id="condition" style="padding-left:19px;"></span>
<span id="inputType" style="padding-left:19px;"></span>
我的阿贾克斯代码:
// This function is used to submit for condition fields by ajax
function showCondition(colName) {
if (colName.length == 0) {
document.getElementById("condition").innerHTML="";
return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("condition").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax/entity_report.php?colName="+colName+"&doAction=showCondition",true);
xmlhttp.send();
}
// This function is used to submit for condition fields by ajax
function showInputType(colName) {
if (colName.length == 0) {
document.getElementById("inputType").innerHTML="";
return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("inputType").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax/entity_report.php?colName="+colName+"&doAction=showInputType",true);
xmlhttp.send();
}
我的 PHP-Ajax 代码:
// include all required files for this screen
include("../include/common.php");
include(MODEL . "entity_report_class.php");
// create class object for class function access
$objCallUsers = new Entity_Report();
// call required class file functions
$returnStr = "";
$arrTypex = $objCallUsers->fetch_data_type();
$typex = $arrTypex[$_REQUEST['colName']];
switch($_REQUEST['doAction']) {
case 'showCondition':
$arrCondition = array();
if($typex == 'TB' || $typex == 'TA') {
$arrCondition = array("Equal to","Not equal to","Starts with","Contains any part of word","Contains full word");
}
else if($typex == 'DD' || $typex == 'RD') {
$arrCondition = array("Equal to","Not equal to");
}
$returnStr .= '<select name="lstCondition" id="lstCondition">
<option>--Please Select--</option>';
foreach ($arrCondition AS $condition) {
$returnStr .= '<option>' . $condition . '</option>';
}
$returnStr .= '</select>';
break;
case 'showInputType':
$arrCondition = array();
if($typex == 'TB' || $typex == 'TA') {
$returnStr .= '<input type="text" name="conditionValue" id="conditionValue" value="" />';
}
else if($typex == 'DD' || $typex == 'RD') {
$returnStr .= ' <select name="conditionValue" id="conditionValue"></select>';
}
break;
}
print($returnStr);
它根据第二个函数调用为我提供输出。这两个函数都返回一些东西。
您正在使用全局变量xmlhttp
第二个函数覆盖它。您应该通过使用 var
关键字引入它来使其成为两个函数的本地函数。
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
相关文章:
- 使用返回函数sinde.attr()jquery元素
- 从自执行函数返回函数的Javascript性能命中率
- Node Express Handlebars帮助程序未返回函数的结果
- 未在Firefox中执行PageMethod的返回函数
- 对返回函数的函数感到困惑
- 从承诺返回不返回函数会导致警告
- 从函数返回函数而不调用返回的函数
- Javascript,闭包中的返回函数如何与外部函数连接
- 为什么Coderbyte.com's的Javascript模板喜欢返回函数的原始参数
- 对象函数返回函数而不是值
- 从外部函数(数组)了解返回函数(x)
- 从Javascript类对象返回函数
- 调用Typescript setter don't返回函数,尽管关联的getter可以工作
- 使用依赖注入在 JavaScript 中返回函数
- 通过单击JSP和javascript加载两个返回函数
- 需要说明:无法理解返回函数的javascript
- 简单的onClick返回函数不起作用
- 为什么这个闭包返回函数
- JS函数返回函数供以后使用-未定义参数
- Coffeescription类中的方法返回函数而不是字符串