我想从逗号分隔的字符串变量中删除一个值,例如 hdnListCL ="'ABC','PQR','XYZ'" 我想删除其中的任何一个,如何在不将其转换为数组的情况下做到这一点?html代码
<input type="hidden" name="hdnlistCL" id="hdnlistCL"/>
<table>
<tr>
<td>
<div id="ProjList"><?php print $strLocName; ?></div><br/>
<input type="text" name="txtCommonLocation" id="txtCommonLocation" size="40" value=""/>
<img src="images/plus.gif" title="Click Here" onclick="AddNewLocation()" style='cursor:pointer;' align="right"/> </td>
</tr>
</table>
javascript
<script type="text/javascript" src="../scripts/jquery.min.js"></script>
<script type="text/javascript">
function AddNewLocation()
{
var listCL = "";
this.strProjName;
if ( typeof strProjName == 'undefined' ) {
strProjName = '';
}
var newLoc = document.getElementById('txtCommonLocation').value;
document.getElementById('txtCommonLocation').value = "";
if(document.getElementById('hdnlistCL').value == '')
{
document.getElementById('hdnlistCL').value =newLoc;
}
else
{
document.getElementById('hdnlistCL').value += ","+newLoc;
}
listCL = newLoc;
if(listCL != '')
{
strProjName = strProjName + '<div id="'+listCL+'">'+listCL+'<div class="close" onclick="removeLocation(\''+listCL+'\')"></div></div>';
}
// alert(strProjName);
$('#ProjList').html(strProjName);
}
function removeLocation(pLocation)
{
var hdnListLocation = document.getElementById('hdnlistCL').value;
if(window.confirm("Are you sure you want to delete this?"))
{
url = 'test_st.php';
$.post(
url,
{"act":"Delete","DelLocation":pLocation,"hdnListLocation": hdnListLocation},
function(responseText){
alert(responseText);
return false;
window.location="test_st.php";
},
"html"
);
return false;
}
}
</script>
php代码
<?php
if(isset($_POST['act']))
$act = $_POST['act'];
if($act == "Delete")
{
$arrhdnListLocation = explode(",", $_POST['hdnListLocation']);
if(in_array($_POST['DelLocation'],$arrhdnListLocation))
{
print("I want to remove'".$_POST['DelLocation']."' from hdnlistCL");
exit();
}
else
{
print("No");
exit();
}
}
?>
当我单击关闭按钮时,我想从 hdnlistCL 中删除该位置。我怎么能这样做?hdnListCL 的值为 ABC,PQR,XYZ 我想从中删除 PQR