开发者

Onclick="should javascript go here?"

I am trying to list some students in a loop in PHP with ajax. And i am going to use the return data to show in a div. But also every student should have a link for editing, and it should be done in ajax too. If anyone has a better idea, i really need to listen, but this is as far as i can get. And also there is another problem. If i write the php like this,

echo '<a href="#" onclick="function(){$.ajax({ type: "GET",url: "/actions/liststude开发者_StackOverflow中文版nts.php\",success: function(html)\{$(\"#liststudents\").html(html);}});}\" >Edit</a> - '.$id.' - '.$name.' '.$surname.'<br />';

I get the html as this,

<a href="#" onclick="function(){$.ajax({ type: " get",url:="" "="" actions="" liststudents.php\",success:="" function(html)\{$(\"#liststudents\").html(html);}});}\"="">Edit</a>
 - 3 - name surname
<br>

But there is another problem with my javascript that i get a solid syntax error.

If there is any better way of achieving the same effect, i really need it, because this is not looking good. If there is no other way, if you can help me, ill be very glad Thank you guys


I'd just give you a class such as "edit" and the target the class within a separate js file:

For instance:

<a href="#" class="edit">Edit</edit>

And in the js file

$(".edit").click(function() {
  $.ajax({
    url: "your url here",
    success: function(){
     //Whatever you need to do
    }
  });
});


put an id on your <a id="someid"></a>

after use:

$(function() {
  $("#someid").click(function() {
     // put your code here
  })
})


You could select the element by id or class name and then bind a click event to the element.

$('a').click(function() {
    // ..
});


you must call function, not define it. like this:

<a href="#" onclick="myFunc();">blablabla</a>
<script>
function myFunc(){
  alert('test');
}
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜