如何获取调用函数的按钮的值“value”

I'm currently into a place where I call an Api with Ajax to delete a Client from a table I've. The thing is, that I've previously tried to make a check before ajax is executed, but it doesn't seem to work.

So this time, when Delete button is clicked I want to check first if the user is sure he wants to delete the client, and if true, execute the function to delete it.

The thing is, I've the id into the button like this:

<td class="text-center">
    <a type="button" class="btn btn-danger" value=('+value.id+') onclick="sureAboutDelete()">Delete Client</a>
</td>

And then in .js file I'm trying that:

// Check if user wants to delete Client
function sureAboutDelete(){
    console.log((event.target));
    // var id = Get the value of value attribute
    // Ask for the user if he/she is sure about deleting
    If (true){
        // delete client using ID taken
        deleteClient($id);
    } else {
        // Just close prompt
        return;
    }
}

When using "(event.target)" I can see all the button with the attributes, but putting "(event.target).val" or like this, I can not take the id I want.

Any suggestion?

Thanks !

查看全部
doudu9094
doudu9094
2017/06/11 12:52
  • php
  • api
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复