开发者

dojo framework - event doesn't work

开发者 https://www.devze.com 2023-03-09 00:26 出处:网络
I have a trouble in my code, I want to send an ajax request by clicking a button, but the request is automatically run, even when I don\'t click the button,

I have a trouble in my code, I want to send an ajax request by clicking a button, but the request is automatically run, even when I don't click the button, here is my code:

<script type="text/javascript">

 function set(mode) {

    var nomor_awal = dojo.query("input[name=nomor_awal]");
    v开发者_Python百科ar nomor_akhir = dojo.query("input[name=nomor_akhir]");

    var validGetUrl = "";

    validGetUrl += "nomor_awal="+objNomorAwal.attr("value")+"&";
    validGetUrl += "nomor_akhir="+objNomorAkhir.attr("value");

    dojo.xhrPost({
        url:"<?php echo base_url(); ?>register_perkara/pidana_biasa/"+mode+"/",
        content:{
            filter:validGetUrl
        },
        load:function(response){
            (response!="1")? document.location = window.location: null;
        }
    });
 }

 dojo.ready(function(){
    dojo.connect(dojo.query("input[name=filter]"), "onclick", set("set_filter"));
 }

</script>



<table>
 <tr>
  <td><label for="nomor_awal">Nomor awal</label></td>
  <td><input type="text" name="nomor_awal" size="8" value="" /></td>
 </tr>
 <tr>
  <td><label for="nomor_akhir">Nomor akhir</label></td>
  <td><input type="text" name="nomor_akhir" size="8" value="" /></td>
 </tr>
 <tr>
  <td colspan="2"><input type="button" name="filter" /></td>
 </tr>
</table>

I don't click the filter button but the function are automatically executed, why?


I don't know dojo, but this line

dojo.connect(dojo.query("input[name=filter]"), "onclick", set("set_filter"));

executes the set function and passes the return value to dojo.connect.

You have to pass the function, not call it. So I'm quite sure you want:

dojo.connect(dojo.query("input[name=filter]"), "onclick", function() {
    set("set_filter");
});
0

精彩评论

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

关注公众号