onunix 2012-08-14 17:11:33 3655次浏览 11条回复 0 0 0

点击怎么会没有反应,没有弹出 点击了我 的对话框, 'onclick'=>'alert("点击了我"); 点击为什么不起作用。

echo CHtml::ajaxLink('GO', 'http://localhost/Yii/index.php?r=Test/export',  
array('type'=>'POST'), //there are various other options for jquery ajax  
array('href'=>'http://localhost/Yii/index.php?r=Test/export'),
array(
'onclick'=>'alert("点击了我"); return false;',
 
)); 

哪里有错吗?

  • 回复于 2012-08-14 17:18 举报

    去掉 array('type'=>'POST') 就会有反应,但是 'http://localhost/Yii/index.php?r=Test/export' 不会执行,加上 array('type'=>'POST'), 则 'http://localhost/Yii/index.php?r=Test/export' 会执行,但是点击没有反应。

    我既要有反应,又希望 则 'http://localhost/Yii/index.php?r=Test/export' 能执行,该如何修改?

  • 回复于 2012-08-14 17:54 举报

    把return false;改为return true。

  • 回复于 2012-08-15 08:08 举报

    return false改为return true,还是没有弹出“点击了我”的提示框。

  • 回复于 2012-08-15 08:19 举报

    难道ajaxLink有这个bug?

  • 回复于 2012-08-15 08:59 举报

    看看最后生成的HTML代码~

  • 回复于 2012-08-15 09:47 举报
    echo CHtml::ajaxLink('GO', 'http://localhost/Yii/index.php?r=Test/export',  
    array('type'=>'POST'), //there are various other options for jquery ajax  
    array('href'=>'http://localhost/Yii/index.php?r=Test/export',
    'onclick'=>'alert("点击了我"); return false;',
    )); 
    
  • 回复于 2012-08-15 10:39 举报

    还是舰长比较V5,一针见血。

  • 回复于 2012-08-15 10:41 举报

    对应的源文件
    执行了对网址的访问,但点击无反应:

    <input href="http://localhost/Yii/index.php?r=Test/export" name="yt0" type="button" value="导出到文件" id="yt0" /><a onclick="alert(&quot;点击了我&quot;); return false;" href="http://localhost/Yii/download/abc.csv">下载文件</a>
    

    没有执行,点击有反应:

    <input name="yt0" type="button" value="导出到文件" id="yt0" /><a onclick="alert(&quot;点击了我&quot;); return false;" href="http://localhost/Yii/download/abc.csv">下载文件</a>
    

    我怎么才能既执行对url的访问,又点击产生反应呢?

  • 回复于 2012-08-15 10:54 举报

    多谢,现在既访问了url,又弹出了提示框,但是还有个问题:我发现在IE浏览器的地址栏上变成了新的url,然后跳转到了新的url的页面。其实,我用ajax是希望用这个新的url来执行一些事情,例如,把数据导出到文件,或者修改个什么东西,但是在地址栏不进行跳转。请问这个可以实现么?

  • 回复于 2012-08-15 11:04 举报

    根据舰长的修改后,发现也有点小问题, 使用return false,就不执行 url,当然也不跳转,改成return true,就执行url,但是跳转了。(这句中的:'onclick'=>'alert("点击了我"); return false;',)

  • 回复于 2012-08-15 11:10 举报

    就是说,根据舰长的修改,并且在此基础上,把 return false 改成 return true,可以同时实现执行url和弹出提示框,现在我还希望,对这个新的url的访问是悄悄进行的,在地址栏不发生改变,因为让用户切换到一个新的页面,在我这种情况下,不合适,我原来想ajax就是解决这个问题的,所以才想用ajax。

您需要登录后才可以回复。登录 | 立即注册