变量和jQuery的:如何捕获价值和使用它们(第2部分) [英] variables and jquery: how capture value and use them (part 2)

查看:99
本文介绍了变量和jQuery的:如何捕获价值和使用它们(第2部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:

我从一个ul-li列表中捕获了一个变量



I有很多名字的列表:罗马,米兰,威尼斯...
我记下了这些(罗马的pulsante1,米兰的pulsante2,威尼斯的pulsante3, 。)与一个mouseover事件(寻找这个问题 变量和如果你想知道更多的话,jquery:如何捕获值(第一部分) )。

所以,我现在有一个全局变量叫做$ regionMap,每当ul-li列表中有一个mouseover事件时,其内容都会更改。
因此,现在我可以在其他jQuery脚本中使用 $ regionMap 值而不是其他id值( pulsante1,pulsante2,pulsante3 ... )。 p>

例如我有这个循环:

  $('#pulsante1' ).mousedown(function()//当点击pulsante1时(id为Roma)
{
var $ variab = document.getElementById('pulsante1')。innerHTML; //取名(这里是罗马)
var $ alfa =#+ $ variab; // Roma现在是#Roma
alert(You entered:+ $ alfa); // control
dialog ($ alfa); //调用函数对话框在#Roma值上滚动
});

//这里第一个类似,但是#pulsante1(Roma)有#pulsante2(Milano)
$('#pulsante2')。mousedown(function()
{
var $ variab = document.getElementById('pulsante2')。innerHTML;
var $ alfa =#+ $ variab;
alert(You entered:+ $ alfa ); //控制
对话框($ alfa); //调用函数对话框
});
}); //关闭点击

现在,我想使用 $ regionMap 改为pulsante1,pulsante2 ...但对我来说是不可能的!
我尝试使用 $($ regionMap).mousedown(function()和其他方式( $($ regionMap)。,( $ regionMap)。,$('$ regionMap')。 ....),

但是我总是没有结果!我知道如何传递一个变量吗?

我认为可能有更好的方法来获得类似的结果(例如,对于in *,使用循环*)我不知道如何去做......



对不起我的长文章,对于基础英语感到抱歉,但我不是开发者,而且我已经去了一个大的TILT!



谢谢 解决方案

问题,试试这个。

  $('#country_list')。mousedown(function(e){

// e.target是您点击的元素

var $ variab = e.target.innerHTML;

var $ alfa ='#'+ $ variab; / /罗马现在#Roma

alert(You entered:+ $ alfa); //控制

对话框($ alfa);

});

您的 #country_list 元素将侦听任何mousedown事件。当发生这种情况时,您可以使用 e.target 查找生成事件的元素。


this is my problem:

I have captured a variable from a ul-li list

I have a list with a lot of names: Roma, Milano, Venezia ... I capture the id value of these (pulsante1 for Roma, pulsante2 for Milano, pulsante3 for Venezia, ... ) with a mouseover event (look for this question variables and jquery: how capture value (part 1) if you want to know more).

So, I have now a global variable called $regionMap, and the its content changes every time the ul-li list has a mouseover event. So, now I could use $regionMap value instead of the different id values (pulsante1, pulsante2, pulsante3...) in other jquery scripts.

For example I have this loop:

$('#pulsante1').mousedown(function() // when click over pulsante1 (id value for "Roma")
        {           
var $variab=document.getElementById('pulsante1').innerHTML; // take the name (here Roma)
var $alfa="#"+ $variab;  // Roma is now #Roma
alert("You entered: " + $alfa); //control
dialog($alfa); // calling the function dialog rolling on #Roma value.
});

// here is similar at the first but instead #pulsante1(Roma) you have #pulsante2 (Milano)
$('#pulsante2').mousedown(function() 
        {       
        var $variab=document.getElementById('pulsante2').innerHTML;
        var $alfa="#"+ $variab;
        alert("You entered: " + $alfa); //control
        dialog($alfa); // calling the function dialog
        }); 
                    });//close click

Now, I would like use $regionMap instead pulsante1, pulsante2... but for me is impossible! I try so $($regionMap).mousedown(function() and in other way ( $($regionMap)., ($regionMap)., $('$regionMap'). .... ),

but I have always no results! How can I do? You know how pass a variable?

I think that probably there is a better way to obtain similar result (for example with a loop *for in *) but I don't know how to it...

Sorry for my long post and sorry for the basical english, but I'm not a developer and I have gone in a big TILT!

thanks

解决方案

After looking at your other question, try this.

$('#country_list').mousedown( function( e ) {

  // e.target is the element you clicked

  var $variab = e.target.innerHTML;

  var $alfa= '#' + $variab;  // Roma is now #Roma

  alert("You entered: " + $alfa); //control

  dialog($alfa);

});

Your #country_list element will listen for any mousedown events. When one occurs, you are able to find the element who generated the event with e.target.

这篇关于变量和jQuery的:如何捕获价值和使用它们(第2部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆