Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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
Javascript 如何仅使用unicode箭头在jquery中切换div_Javascript_Jquery_Hide_Show_Collapse - Fatal编程技术网

Javascript 如何仅使用unicode箭头在jquery中切换div

Javascript 如何仅使用unicode箭头在jquery中切换div,javascript,jquery,hide,show,collapse,Javascript,Jquery,Hide,Show,Collapse,我试图用箭头切换div;这是我目前掌握的代码: $('.hide show').hide(); $('.toggle year')。在('单击',函数()上){ $(this.html($(this.text().substr(0,4)='Hide'?'&'9660;':'Hide&'9650;'); $('.hide show')。切换('slow'); }); 这里有内容 最简单的方法是删除所有不需要的文本,然后比较文本当前是否等于向上或向下箭头: //隐藏页面加载时要隐藏的文本: $

我试图用箭头切换div;这是我目前掌握的代码:

$('.hide show').hide();
$('.toggle year')。在('单击',函数()上){
$(this.html($(this.text().substr(0,4)='Hide'?'&'9660;':'Hide&'9650;');
$('.hide show')。切换('slow');
});

这里有内容

最简单的方法是删除所有不需要的文本,然后比较文本当前是否等于向上或向下箭头:

//隐藏页面加载时要隐藏的文本:
$('.hide show').hide();
//选择与提供的CSS选择器匹配的所有元素
//并绑定on()方法的匿名函数
//作为“单击”事件的事件处理程序:
$('.toggle year')。在('单击',函数()上){
$(this).text(函数(\ux,currentText){
//_u是当前元素的索引
//jQuery集合中检索到的所有元素;
//currentText是对当前文本内容的引用
//来自jQuery集合的当前元素的。
//这里我们使用一个条件运算符来更新
//当前元素的文本。如果当前文本为
//等于▼' 然后我们把它改成'▲' 如果它
//不等于▼' 然后我们将其设置为'▼':
返回currentText==”▼" ? "▲" : "▼";
});
//然后切换隐藏对象的可见性
//要素:
$('.hide show')。切换('slow');
});
/*我们使用的是,而不是
导航到网站的一个新区域,所以我们在这里
将其样式设置为类似于(假设是
您的偏好):*/
一年一次{
边界:0;
背景色:继承;
文字装饰:下划线;
颜色:#00f;
大纲:0;
}

▼
这里有内容

最简单的方法是删除所有不需要的文本,然后比较文本当前是否等于向上或向下箭头:

//隐藏页面加载时要隐藏的文本:
$('.hide show').hide();
//选择与提供的CSS选择器匹配的所有元素
//并绑定on()方法的匿名函数
//作为“单击”事件的事件处理程序:
$('.toggle year')。在('单击',函数()上){
$(this).text(函数(\ux,currentText){
//_u是当前元素的索引
//jQuery集合中检索到的所有元素;
//currentText是对当前文本内容的引用
//来自jQuery集合的当前元素的。
//这里我们使用一个条件运算符来更新
//当前元素的文本。如果当前文本为
//等于▼' 然后我们把它改成'▲' 如果它
//不等于▼' 然后我们将其设置为'▼':
返回currentText==”▼" ? "▲" : "▼";
});
//然后切换隐藏对象的可见性
//要素:
$('.hide show')。切换('slow');
});
/*我们使用的是,而不是
导航到网站的一个新区域,所以我们在这里
将其样式设置为类似于(假设是
您的偏好):*/
一年一次{
边界:0;
背景色:继承;
文字装饰:下划线;
颜色:#00f;
大纲:0;
}

▼
这里有内容

另一种解决方案可以基于:

$('.hide show').hide();
$('.toggle year')。在('单击',函数()上){
var ntext=this.text.trim().charCodeAt(0)='9650'?'▼;':'▲;'
$(this.html(ntext);
$('.hide show')。切换('slow');
});

这里有内容

另一种解决方案可以基于:

$('.hide show').hide();
$('.toggle year')。在('单击',函数()上){
var ntext=this.text.trim().charCodeAt(0)='9650'?'▼;':'▲;'
$(this.html(ntext);
$('.hide show')。切换('slow');
});

这里有内容

第三种可能的解决方案是使用
String.fromCharCode()
()进行比较

$('.hide show').hide();
$('.toggle year')。在('单击',函数()上){
$(this.html($(this.text()==String.fromCharCode(9660)?“▲;”:“▼;”);
$('.hide show')。切换('slow');
});

这里有内容

第三种可能的解决方案是使用
String.fromCharCode()
()进行比较

$('.hide show').hide();
$('.toggle year')。在('单击',函数()上){
$(this.html($(this.text()==String.fromCharCode(9660)?“▲;”:“▼;”);
$('.hide show')。切换('slow');
});

这里有内容

更干净的方法是:

  • 将每组可折叠内容包装在一个
  • 在每次单击时,向该包装器div添加或删除一个
    .active
  • 将图标配置保留在css中
  • 使用简单的三行javascript代码切换活动类(jquery
    toggleClass()
    函数)
$('.collapsable按钮')。单击(函数(){
$(this.parent().toggleClass('active');
});
。可折叠按钮:之后{
内容:“▼";
}
.collapsable.active按钮:之后{
内容:“▲";
}
.collapsable:未(.active).内容{
显示:无;
}

这里有内容

更干净的方法是:

  • 将每组可折叠内容包装在一个
  • 在每次单击时,向该包装器div添加或删除一个
    .active
  • 将图标配置保留在css中
  • 使用简单的三行javascript代码切换活动类(jquery
    toggleClass()
    函数)
$('.collapsable按钮')。单击(函数(){
$(this.parent().toggleClass('active');
});
。可折叠按钮:之后{
内容:“▼";
}
.collapsable.active按钮:之后{
内容:“▲";
}
.collapsable:未(.active).内容{
显示:无;
}

内容来了