我有一個div與class ='divclass'和其中的一些文本...現在我想顯示一個彈出式菜單,當用戶鼠標懸停在div中的任何單詞...彈出窗口也會顯示該單詞?哪個用戶具有mousedover鼠標......我們如何才能做到這一點..jquery得到選定的詞
1
A
回答
0
我同意bicccio。爲了節省時間,你還可以自動化周圍用下面的代碼的每個字跨距創建,然後安裝該事件顯示文本:
$(function() {
var text = $(".divclass").text();
text = "<span>" + $.trim(text) + "</span>";
text = text.replace(/\s/g, "</span><span> ")
$(".divclass").html(text);
$(".divclass span").live("mouseover", function() {
alert($(this).text());
});
});
1
我認爲你必須與周圍像<span>
一個元素,那麼任何字:
$('.divclass span').mouseover(function(){
alert($(this).text());
// or showMyPopup($(this).text());
});
0
試試這個:
$(document).ready(function(){
var all_words=$("#divclass").text().split(' ');
$("#divclass").html("");
$.each(all_words, function(i,val)
{
$('<span/>').text(val +" ").appendTo("#divclass");
});
$("#divclass span").live("mouseover",function(){
alert($(this).text());
});
});
看到它住在這裏:http://jsfiddle.net/jqLw8/
0
你可以這樣做:
function divideTextInSpans(text){
return $.map(text.split(" "), function(word){
return '<span class="word">'+word+'</span>';
}).join(' ');
}
$(document).ready(function(){
$(".divclass").each(function(){
var newInnerHtml = divideTextInSpans($(this).text());
$(this).html(newInnerHtml);
$(this).find(".word").hover(function(){
//Show your popup code here
$(this).css("backgroundColor", "yellow"); //Highlight
}, function(){
//Hide your popup code here
$(this).css("backgroundColor", ""); //Un-Highlight
});
});
});
我們」什麼重做是將每個單詞放在div中的一個單獨的跨度中,然後綁定一個懸停事件。
相關問題
- 1. Jquery得到選定的複選框
- 2. jquery從textarea得到隨機單詞
- 3. jQuery獲得選定的選項問題
- 4. 的JQuery得到單選框選擇
- 5. jquery得到選定的單選按鈕值
- 6. html.dropdownlistfor得到選定的值
- 7. 得到選定的行
- 8. 得到選項值jQuery中
- 9. jQuery的謂詞選擇
- 10. 的ListView非選定項得到選擇
- 11. jQuery Mobile的定製Flipbox得到選擇的值
- 12. 得到孩子選擇的訂單jquery
- 13. 得到jquery ui multiselect未選中的值
- 14. JQuery的:得到單選按鈕值
- 15. 得到一個選擇變量的JQuery
- 16. 從@HtmlDropDown得到選定值
- 17. 使用DropDownListFor jquery沒有得到當前選定的值
- 18. 如何得到一個jQuery綁定的活選擇器結果?
- 19. 如何從jquery datepicker得到選定的日/月和年
- 20. Jquery自動完成選定的ID沒有得到保存
- 21. jQuery從selectbox中得到選定的值不起作用
- 22. jQuery得到選擇的選項,並選擇另一個選擇
- 23. 的jQuery按鈕的onclick得到家長選擇選項選擇
- 24. JQuery的得到一個複選框的選項被選中
- 25. 得到的jQuery
- 26. 得到的jQuery
- 27. 得到的jQuery
- 28. 得到的jQuery
- 29. 得到的jQuery
- 30. 得到jQuery的
如果你可以拆分html源代碼中的單詞(例如用span來包裝每個單詞),這將很容易。然後你可以綁定mouseover/mouseout事件來獲得你的結果。你是否認爲你可以改變HTML(我的意思是你有權這樣做) – CrisDeBlonde 2011-05-03 08:01:33