Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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中href中#之后的所有内容_Jquery_Html - Fatal编程技术网

删除jquery中href中#之后的所有内容

删除jquery中href中#之后的所有内容,jquery,html,Jquery,Html,我在class li classpivot nav item中有链接,其中包含href=#sometext。如果满足#的特定条件,我想删除所有内容。我正在使用以下代码查看用户是否已触摸屏幕以添加用户正在触摸的类。因此,如果用户触摸了屏幕,我想在#之后删除所有内容 window.addEventListener('touchstart', function onFirstTouch() { // we could use a class document.body.classList.add('u

我在class li class
pivot nav item
中有链接,其中包含
href=#sometext
。如果满足#的特定条件,我想删除所有内容。我正在使用以下代码查看用户是否已触摸屏幕以添加用户正在触摸的类
。因此,如果用户触摸了屏幕,我想在#之后删除所有内容

window.addEventListener('touchstart', function onFirstTouch() {
// we could use a class
document.body.classList.add('user-is-touching');

// or set some global variable
window.USER_IS_TOUCHING = true;

// or set your app's state however you normally would

// Remove mouse-related events here

 $(".o-c, .c-f, .i-c, .c-u").unbind('mouseenter').unbind('mouseleave')

// we only need to know once that a human touched the screen, so we can stop 
listening now
window.removeEventListener('touchstart', onFirstTouch, false);
}, false);
window.addEventListener('touchstart',函数onFirstTouch(){
//我们可以去上课
document.body.classList.add('user-is-touching');
//或者设置一些全局变量
window.USER_为_=true;
//或者以通常的方式设置应用程序的状态
//在此处删除与鼠标相关的事件
$(“.o-c、.c-f、.i-c、.c-u”)。解除绑定('mouseenter')。解除绑定('mouseleave'))
//我们只需要知道一次有人触摸了屏幕,这样我们就可以停止听了
removeEventListener('touchstart',onFirstTouch,false);
},假);
$(“.o-c”)。单击(函数(){
if($('body').hasClass('user-is-touching')){
}else{//做点别的
}
});

  • 您可以使用
    attr()
    设置链接的
    href
    属性

    $('pivot nav item')。在('click',function()上{
    $(this.find('a').attr('href','#');
    });
    
    
    

    是只有一个
    还是有多个?我有多个li,其中clas
    pivot nav item
    有一个,而您不使用
    a.split('.#')[0]
    在touchstart函数或click函数中?您的条件是否假设将href设为
    .
    ?我正在尝试添加以下内容:$(.o-c”)。单击(function(){if($('body').hasClass('user-is-touching'){$(“.o-c”).find('a').attr('href','#');但在这种情况下似乎不起作用,您的代码是
    $(.o-c”).attr('href','#')
    请告诉我它是否起作用