Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于查找字符串的jquery选择器 $(函数(){ var one=‘twitter’; 变量二='about'; 变量三=‘接触’; var-four='exp'; 风险值五=价格; $('#twitter')。悬停(函数(){ $(this.append(“”+one+””); $('.hvtext').css({左:'1.7em', 底部:“0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#about')。悬停(函数(){ $(this.append(“”+two+””); $('.hvtext').css({左:'1.7em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#contact')。悬停(函数(){ $(this).append(“”+three+”) $('.hvtext').css({左:'1.2em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $(“#体验”)。悬停(函数(){ $(this.append(“”+four+””); $('.hvtext').css({左:'2.3em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#prices')。悬停(函数(){ $(this.append(“”+five+””); $('.hvtext').css({左:'2em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); 一、点击(函数(){ 警报(“元素存在”); }); });_Jquery_Html_Css - Fatal编程技术网

用于查找字符串的jquery选择器 $(函数(){ var one=‘twitter’; 变量二='about'; 变量三=‘接触’; var-four='exp'; 风险值五=价格; $('#twitter')。悬停(函数(){ $(this.append(“”+one+””); $('.hvtext').css({左:'1.7em', 底部:“0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#about')。悬停(函数(){ $(this.append(“”+two+””); $('.hvtext').css({左:'1.7em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#contact')。悬停(函数(){ $(this).append(“”+three+”) $('.hvtext').css({左:'1.2em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $(“#体验”)。悬停(函数(){ $(this.append(“”+four+””); $('.hvtext').css({左:'2.3em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#prices')。悬停(函数(){ $(this.append(“”+five+””); $('.hvtext').css({左:'2em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); 一、点击(函数(){ 警报(“元素存在”); }); });

用于查找字符串的jquery选择器 $(函数(){ var one=‘twitter’; 变量二='about'; 变量三=‘接触’; var-four='exp'; 风险值五=价格; $('#twitter')。悬停(函数(){ $(this.append(“”+one+””); $('.hvtext').css({左:'1.7em', 底部:“0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#about')。悬停(函数(){ $(this.append(“”+two+””); $('.hvtext').css({左:'1.7em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#contact')。悬停(函数(){ $(this).append(“”+three+”) $('.hvtext').css({左:'1.2em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $(“#体验”)。悬停(函数(){ $(this.append(“”+four+””); $('.hvtext').css({左:'2.3em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); $('#prices')。悬停(函数(){ $(this.append(“”+five+””); $('.hvtext').css({左:'2em',下:'0.1em'}); },函数(){ $('.hvtext').hide(); }); 一、点击(函数(){ 警报(“元素存在”); }); });,jquery,html,css,Jquery,Html,Css,我试图找到一种调用.hvtext类作为选择器的方法,该选择器稍后将用作点击事件 问题是,该类是通过动态添加的。append,我尝试使用。is(':visible'),但找不到它 另一个问题:既然它是一个类,我也想单独识别它们,我应该只使用Id吗 为了解决这个问题,我尝试通过为每个文本添加一个var来区分它们,希望以后可以将它们作为事件调用,但因为它们只是可变字符串,不是元素,所以我不能 我有没有办法做到这一点 问题是,该类是通过.append动态添加的 如果是动态添加的,则需要在上使用: $(f

我试图找到一种调用
.hvtext
类作为选择器的方法,该选择器稍后将用作点击事件

问题是,该类是通过
动态添加的。append
,我尝试使用
。is(':visible')
,但找不到它

另一个问题:既然它是一个类,我也想单独识别它们,我应该只使用Id吗

为了解决这个问题,我尝试通过为每个文本添加一个
var
来区分它们,希望以后可以将它们作为事件调用,但因为它们只是可变字符串,不是元素,所以我不能

我有没有办法做到这一点

问题是,该类是通过.append动态添加的

如果是动态添加的,则需要在上使用

$(function(){
    var one = 'twitter';
    var two = 'about';
    var three = 'contact';
    var four = 'exp';
    var five = 'price';

    $('#twitter').hover(function(){
        $(this).append('<p class="hvtext" id="twitterz">'+ one + '</p>');
        $('.hvtext').css({left:'1.7em',
                          bottom: '0.1em'});

    }, function(){
        $('.hvtext').hide();
    });
    $('#about').hover(function(){
        $(this).append('<p class="hvtext">' + two + '</p>');
        $('.hvtext').css({left:'1.7em', bottom:'0.1em'});
    }, function(){
        $('.hvtext').hide();
    });
    $('#contact').hover(function(){
        $(this).append('<p class="hvtext">'+ three + '</p>')
        $('.hvtext').css({left:'1.2em', bottom:'0.1em'});
    }, function(){
        $('.hvtext').hide();
    });
    $('#experience').hover(function(){
        $(this).append('<p class="hvtext">'+ four + '</p>');
        $('.hvtext').css({left:'2.3em', bottom:'0.1em'});
    }, function(){
        $('.hvtext').hide();
    });
    $('#prices').hover(function(){
        $(this).append('<p class="hvtext">'+ five + '</p>');
        $('.hvtext').css({left:'2em',bottom:'0.1em'});
    }, function(){
        $('.hvtext').hide();
    });

    one.click(function(){
        alert('element exists');
    });



});
既然这是一个类,我也想分别识别它们,我应该吗 就用身份证

为什么??这就是
$(this)
的用武之地。如果需要传递数据,我会执行以下操作:

$('#prices').on('click', '.hvtext', function() {/*click stuff here*/});


你似乎想在这里添加一个工具提示,你考虑过了吗?

为什么人们不能使用回车……呜呜,谢谢,利亚姆:我不明白这一部分:“我正在试图找到一种调用.hvtext的方法”你的代码中哪里卡住了?我看到很多$('.hvtext'),请澄清您的问题。顺便说一句,如果只是用于样式设置,那么使用CSS规则在您的特定示例中,您将“one”设置为字符串,该字符串没有单击绑定。如果您的实际代码反映了相同的错误,那么您应该实际使用
$('#'+one).on('click',function(){/*code*/})
有什么原因不能在标记中写入.hvtext元素,而只能在js中选择/更改它吗?添加了一些更详细的信息,因为您似乎需要根据悬停的位置调整左侧和底部。
$('#experience').hover(function(){
    var newHvText = $('<p class="hvtext">'+ four + '</p>');
    newHvText.data('leftEm', '2em');
    $(this).append(newHvText);
}, function(){
    $('.hvtext').hide();
}););
$('#prices').on('click', '.hvtext', function() {/*click stuff here*/
       var thisIsTheClickedElement =  $(this);
       var leftEm = thisIsTheClickedElement.data('leftEm');
       $('.hvtext').css({left:leftEm});
});