$("body").delegate("#AddShopingCart", "click", function() {
var me = $(this)
$.ajax({
type: 'POST',
url: $Maticsoft.BasePath + "ShoppingCart/AddShopCart",
data: {
Sku: me.attr('sku'),
Count: "1",
Productid: me.attr('productid')
},
dataType: 'json',
timeout: 3000,
cache: false,
success: function(data) {
if (data.DATA == "WeiDengLu") {
window.location.href = ($Maticsoft.BasePath + "a/l")
} else {
alert("加入")
}
},
error: function(msg) {
alert("错误")
}
})
})
</script>
在function(e){}函数体中用语句
e.preventDefault()
$('#id').click(function(e) {
e.preventDefault()
})
错在:这个是jquery代码,没有加载jquery库就不能运行,其次,这个return false不对。
扩展资料:js事件绑定方式总结(click事件)
1、HTML onclick事件属性
<button onclick="clickMe(this)">click me</button>
function clickMe(this) {2 alert("click me")3 }
2、JavaScript onclick事件
<button id="button">click me</button>
document.getElementById("button").onclick=clickMe
3、IE4+<script for>
1 <button id="button1">click me</button>
1 <script for="button1" event="onclick">2 alert("click me")3 </script>
4、IE5/windows attachEvent()方法
<button id="button2">click me</button>
document.getElementById("button2").attachEvent("onclick",clickMe)
5、W3C DOM addEventListener()方法
<button id="button3">click me</button>
document.getElementById("button3").addEventListener("click",clickMe)