使用jQuery更改字幕文本和速度

时间:2011-02-03 17:34:24

标签: jquery marquee

我正在尝试使用jQuery更改选框标记内的文本和选取框的速度。

在我的脚本中,我有以下内容:

$("div.change").click( function() {     
  //here I want to make the script to change the text to anything else ...      
}); 

在我的HTML中:

<div id="marq"><marquee id="title" scrollamount="5">MY TEXT</marquee></div>

<div class="change">Click Here To Change The Text in Marquee</div>

如何更改选框内的速度和文字?

提前致谢。

2 个答案:

答案 0 :(得分:2)

字幕标记is not in the HTML specification因此无法保证在较新的浏览器中支持它。它的使用非常气馁。

如果您必须有滚动文字,则可以jquery plugins执行此操作。

答案 1 :(得分:0)

我同意你不应该使用marquee元素,但如果必须,那么要复制文本并加倍速度,请执行以下操作:

$('div.change').click(function(){
    var marq  = $('marquee#marq');
    var speed = 2 * marq.attr('scrollamount'); // double the current speed
    var text = $('textarea#newtext').text();   // Get new text
    $(marq).text(text).attr({scrollamount: speed});
});

这假定用户已使用新文本填充了id为“newtext”的textarea元素。

P.S。你为什么在选框上有一个ID,但在change-div上有一个类。此外,最好使用按钮标签让用户点击,而不是点击div,它更直观。