所以我的jQuery看起來不錯,但由於某種原因,當我點擊按鈕console.log
不會觸發。任何人都知道這可能是爲什麼?jQuery沒有讀取點擊
這是我用過的jQuery的鏈接。對困惑感到抱歉。這個是在標題中。雖然它仍然沒有工作。
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type = "text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email Parser GUI</title>
<link rel="stylesheet" type="text/css" href="Styles.css" />
<script>
$(document).ready(function(){
console.log("TEST ABOVE CLICKS");
$("#btnOn").click(function() {
console.log("TEST btnOn");
var value = 1;
$.ajax({
type: "POST",
url: "URLphp",
data: {value : value},
dataType: "json",
async: true,
beforeSend: function(){
console.log("check before send of ajax in btnOn");
},
success: function(data) {
console.log(data);
}
});
});
$("#btnOff").click(function() {
console.log("TEST btnOff");
var value = 0;
$.ajax({
type: "POST",
url: "URL.php",
data: {value : value},
dataType: "json",
async: true,
beforeSend: function(){
console.log("check before send of ajax in btnOff");
},
success: function(data) {
console.log(data);
}
});
});
});
</script>
</head>
然後在身體標記
<div class="form-group">
<label class="col-md-4 control-label" for="btnOn">On/Off</label>
<div class="col-md-8">
<button id="btnOn" name="btnOn" value="1" class="btn btn-success">On</button>
<button id="btnOff" name="btnOff" value="0" class="btn btn-danger">Off</button>
</div>
</div>
任何幫助,將不勝感激。謝謝。
你包括jQuery庫文件? – brk
哪個console.log不會觸發? –
@MrGeek我認爲第二個(「測試btnOn」) –