Yii Framework Forum: CHtml::linkButton 和 CHtml::link怎么防止2次提交? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CHtml::linkButton 和 CHtml::link怎么防止2次提交? Rate Topic: -----

#1 User is offline   sharehua 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 456
  • Joined: 30-December 08

Posted 27 October 2010 - 08:13 AM

怎样添加js,设置link点击后无效。
YII2 技术群【QQ群--146409855】,欢迎朋友,拒绝过客
0

#2 User is offline   Davidhhuan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 08-September 09

Posted 27 October 2010 - 08:45 AM

有一个很笨的方法:

<a href="http://www.baidu.com" id="clickOnce">tset</a>
<script type="text/javascript">
$("#clickOnce").click(function() {
   $(this).attr("href", "####");
});
</script>

no pain, no gain...

My Blog : http://cnblogs.com/davidhhuan
My website: http://sharefamily.net/
0

#3 User is offline   sharehua 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 456
  • Joined: 30-December 08

Posted 27 October 2010 - 08:46 AM

这不是 CHtml的方法啊。
YII2 技术群【QQ群--146409855】,欢迎朋友,拒绝过客
0

#4 User is offline   Davidhhuan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 08-September 09

Posted 27 October 2010 - 08:54 AM

所谓的CHtml方法是指什么?这样?

CHtml::link(
    "TestLink",
    "http://www.baidu.com",
    array(
        "onclick"=>"this.href='####'",
    )
);

no pain, no gain...

My Blog : http://cnblogs.com/davidhhuan
My website: http://sharefamily.net/
0

#5 User is offline   sharehua 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 456
  • Joined: 30-December 08

Posted 27 October 2010 - 08:58 AM

例如:
echo CHtml::linkButton('点击',array('submit'=>'','params'=>array('command'=>'attendance','frequencySectionId'=>11)))
YII2 技术群【QQ群--146409855】,欢迎朋友,拒绝过客
0

#6 User is offline   sharehua 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 456
  • Joined: 30-December 08

Posted 27 October 2010 - 10:19 AM

这样可以解决,但也太不科学了。哪个有更好的做法?
echo CHtml::linkButton('点击',array('onclick'=>"$('body').undelegate('#yt0','click');",'submit'=>'','params'=>array('command'=>'attendance','frequencySectionId'=>11)))
YII2 技术群【QQ群--146409855】,欢迎朋友,拒绝过客
0

#7 User is offline   sharehua 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 456
  • Joined: 30-December 08

Posted 27 October 2010 - 10:51 AM

改进一下

echo CHtml::linkButton('点击',array('id'=>'xx','onclick'=>"$('body').undelegate('#xx','click');",'submit'=>'','params'=>array('command'=>'attendance','frequencySectionId'=>11)))
YII2 技术群【QQ群--146409855】,欢迎朋友,拒绝过客
0

#8 User is offline   delphiss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 27-April 09

Posted 27 October 2010 - 09:11 PM

我觉得让按钮变灰失效就行,用户也知道不能点了,否则他还点啊点的,多浪费鼠标
0

#9 User is offline   sharehua 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 456
  • Joined: 30-December 08

Posted 27 October 2010 - 11:54 PM

A变灰也能点,和button不一样。有些入门级朋友 把双击当单击用。结果就两条记录了。
YII2 技术群【QQ群--146409855】,欢迎朋友,拒绝过客
0

#10 User is offline   Thinking 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 29-June 09

Posted 19 February 2011 - 08:15 AM

防止二次提交controller里有个refresh方法。
0

#11 User is offline   hibby 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-August 11

Posted 29 August 2011 - 04:46 AM

在处理结束前添加 $this->refresh();
0

#12 User is offline   williamjxj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 17-July 12

Posted 26 July 2012 - 06:33 PM

to prevent multi-submit, the way should like this:

$('a.class').click(function(event) {

// prevent a.href's summit
event.preventDefault();

ahref = $(this).attr('href');

// here you can add as many as functions you want this click do. like:
// $.ajax();
// $.load();
// $.get();
// $.post();
// $(this).css().animate().....

// and finally, sumbit the default
$.get(ahref, callback);

//return false is a must.
return false;
}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users