Jquery模板href单击

时间:2013-07-29 19:53:56

标签: jquery href jquery-templates

我在jquery模板中有这个href怎么能让它在单击它时会转到javascript函数?

<a href="#" id="number" class="rowSelection btn_simple" data-url="/Marketing/Moby/SelectPhoneNumber" data-redirect="/Marketing/Moby" data-value="${PhoneNumber}">Select</a><br/>

3 个答案:

答案 0 :(得分:1)

只需将此<a href="#"替换为:<a href="yourfunction()"

甚至更好你可以保留html,并将其添加到jQuery上,如:

$('#number').click(function(e){
//your code here
});

<强> Demo here

答案 1 :(得分:0)

<a href="#" onclick="yourfunction();return false;" id="number" class="rowSelection btn_simple" data-url="/Marketing/Moby/SelectPhoneNumber" data-redirect="/Marketing/Moby" data-value="${PhoneNumber}">Select</a><br/>
or 
$(document).on("click", "#number", function (e) {
    event.preventDefault();
    // function body
});

答案 2 :(得分:0)

您必须将href="#"替换为href="yourFunction();"

<a href="yourFunction();" id="number" class="rowSelection btn_simple" data-url="/Marketing/Moby/SelectPhoneNumber" data-redirect="/Marketing/Moby" data-value="${PhoneNumber}">Select</a><br/>

或者这个:

$("#number").click(function() {
    // Your function
});