1

我是 Jquery 的新手...我正在开发一个使用 ruby​​ on rails 的应用程序。在这里,我要做的是从 Jquery 调用控制器操作,并在具有打字机效果的 div 中显示其输出。现在我想在单击哪个打字机效果开始时显示一个按钮“播放”,并且“播放”按钮更改为“停止”。在停止它时,它会转换为“播放”并开始播放等等。为此,我在 Jquery 上使用了此代码。

var text="content of text here";
var delay=50;
var currentChar=1;
var destination="[not defined]";

function set_file(id,time,user,node,activity) 
{
       var filename = "";
       filename = user+"_"+node+"_"+activity+"_"+time;

       jQuery("#play_"+id).click(function(event){
       event.preventDefault();
       jQuery("#img_"+id).attr('src',"/images/stop_images.png");
       jQuery("#img_"+id).attr('title',"Stop");
       jQuery(this).attr('id','stop_'+id);
       jQuery.get('/requests/download_log/?filename=' + filename, function(data) {
       startTyping(data, 50, "request_"+id);
       });
      jQuery("#stop_"+id).click(function(){
            jQuery("#img_"+id).attr('src',"/images/play_images.png");
            jQuery("#img_"+id).attr('title',"Play");
                    text="content of text here";
                    delay=50;
                    currentChar=1;
                    destination="[not defined]";
            });
  }

 function startTyping(textParam, delayParam, destinationParam)
 {
      text=textParam;
      delay=delayParam;
       currentChar=1;
    destination=destinationParam;
    type();
   }
 function type()
 {
  if (document.getElementById)
 {
   var dest=document.getElementById(destination);
  if (dest)
  {
  dest.innerHTML=text.substr(0, currentChar);
  currentChar++
    if(currentChar <= text.length)
     {
            setTimeout("type()", delay);
      }
  }
  }
 }

我的查看页面是

<% i = 1%>
 <%=link_to_function result.time,:id => "log_#{i}",:onclick => "set_file(#{i},'#{time_val}','#{result.user}','#{result.nodeip}','#{result.activityuser}')" %>
<div id = "file_<%= i %>" class = "file">
<%= link_to_function image_tag("play_images.png",:width => 30, :height => 30,:align => 'left', :title => 'Play', :id => "img_#{i}"),:id => "play_#{i}"%>
<b><h7 id= "fname_<%= i %>" class = "h7">""</h7></b>
<%= link_to_function image_tag("images.jpeg",:align => 'right'), :id => "close_#{i}"%>
<div id = "request_<%= i%>" class = "request">
</div>
</div>
<%i = i + 1%>

请任何人告诉我我该怎么做,我怎么能停止打字机模式?

4

0 回答 0