我试图在点击按钮时设置php变量,这是一些输入模式,如addentry,editentry,经过大量研究后我发现jquery ajax是在click函数上设置php变量的方法。但是在调试模式下我看到的是光标永远不会进入$ .ajax它只是跳过它
插件
<!-- jQuery -->
<!-- jQuery-ui -->
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
html内容
<div class = "container">
<div class = "acdetail">
<form action = "" method = "POST" enctype = "multipart/form-data" class = "frmac" >
<input type="text" name="acname" id="acname" class="form-control" onfocus = 'SetColor(this.id)' onblur = 'ReleaseColor(this.id)'></br></br>
<input type="text" name ="acopen" id="acopen" class="form-control" onfocus = 'SetColor(this.id)' onblur = 'ReleaseColor(this.id)'></br></br>
<select name="crdr" id = "crdr" class="form-control" onfocus = 'SetColor(this.id)' onblur = 'ReleaseColor(this.id)'>
<option value = "D">Debit</option>
<option value = "C">Credit</option>
</select></br></br>
<select name="yn" id = "yn" class="form-control" onfocus = 'SetColor(this.id)' onblur = 'ReleaseColor(this.id)'>
<option value = "Y">Yes</option>
<option value = "N">No</option>
</select></br></br>
<button type="button" name="addentry" value="add" id="add" class="btn btn-info" onclick = 'BtnControl(this.id,"acname")'>Add</button>
<input type="submit" name="saveentry" value="Save" id="save" class="btn btn-info" onclick = 'BtnControl(this.id)'>
<button type="button" name="editentry" value="edit" id="edit" class="btn btn-info" onclick = 'BtnControl(this.id,"acname")'>edit</button>
<button type="button" name="cancel" value="cancel" id="cancel" class="btn btn-info" onclick = "ClearControl('acdetail');BtnControl(this.id);">Cancel</button>
<input type="submit" name="deleteentry" value="delete" id="delete" class="btn btn-info" onclick = 'BtnControl(this.id)'>
</form>
</div>
</div>
jquery函数是
//Button enable disable
function BtnControl(idname,setfocus = ""){
var curclass;
switch(idname){
case 'load':
case 'cancel':
case 'delete':
$("#add").attr('disabled',false)
$("#save").attr('disabled',true)
$("#edit").attr('disabled',false)
$("#cancel").attr('disabled',false)
$("#delete").attr('disabled',true)
$("#add").focus();
break;
case 'add':
$("#add").attr('disabled',true)
$("#save").attr('disabled',false)
$("#edit").attr('disabled',true)
$("#cancel").attr('disabled',false)
$("#delete").attr('disabled',true)
document.getElementById(setfocus).focus();
var curclass = 'add'
break;
case 'save':
$("#add").attr('disabled',true)
$("#save").attr('disabled',false)
$("#edit").attr('disabled',true)
$("#cancel").attr('disabled',false)
$("#delete").attr('disabled',true)
$("#add").focus();
break;
case 'edit':
$("#add").attr('disabled',true)
$("#save").attr('disabled',false)
$("#edit").attr('disabled',true)
$("#cancel").attr('disabled',false)
$("#delete").attr('disabled',false)
document.getElementById(setfocus).focus();
var curclass = 'edit'
break;
}
$.ajax({
type: 'POST',
url : 'entrymode.php',
data: 'flag='+curclass,
datatype: 'text',
success: function(msg){
$('#m').html(msg)
}
})
}
url php页面是
<?php
global $entrymode;
global $addentry;
global $editentry;
global $viewentry;
global $deleteentry ;
global $flag ;
echo '(manoj)';
switch($flag){
case 'add':
$entrymode = $addentry;
break;
case 'edit':
$entrymode = $editentry;
break;
case 'delete':
$entrymode = $deleteentry;
break;
}
?>