Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.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/2/jquery/83.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 仅当jquery中的按钮中有值时才显示按钮?_Javascript_Jquery_Button - Fatal编程技术网

Javascript 仅当jquery中的按钮中有值时才显示按钮?

Javascript 仅当jquery中的按钮中有值时才显示按钮?,javascript,jquery,button,Javascript,Jquery,Button,我有一个这样的按钮: <button> {{ pages.first }}</button> <button>{{ pages.last }}</button> 我做错了什么 我的按钮在代码中看起来像这样: <button class="next_prev" onclick="" disabled>{% get_pages %} {{ pages.next }}</button> <button class=

我有一个这样的按钮:

  <button> {{ pages.first }}</button>

 <button>{{ pages.last }}</button>
我做错了什么

我的按钮在代码中看起来像这样:

<button class="next_prev" onclick="" disabled>{% get_pages %} {{ pages.next }}</button> <button class="next_prev" onclick="" id="last_button" disabled>{% get_pages %} {{ pages.last }}</button>
{%get_pages%}{{pages.next}{%get_pages%}{{pages.last}
您需要使用
text()
而不是
val()
。。在有多个按钮的情况下,你需要在按钮之间循环

试试这个

 $.each($("button"),function(){  //in case of multiple button
  if(!$(this).text()){
    $(this).hide();
   }
  else {
    $(this).show();
  }
})

使用
.each()
遍历并检查所有按钮:


您的代码
.val()
将适用于
按钮

使用
文本
而不是
val
将起作用

if(!$('button').text()){
   $('button').hide();
}
else {
  $('button').show();
}

我想你想要
text
here not
val
…不工作我的整个按钮看起来是这样的:{%get_pages%}{{pages.next}{%get_pages%}{{{pages.last}}我得到的按钮即使是空的。只使用一个按钮:(你可以尝试在提琴中添加按钮..即使有100个按钮也可以..你能给我看一下你的按钮的htmL吗?确保另一个按钮是空的..我猜按钮中有一些文本,让它不会隐藏..可能是罪魁祸首..
{%get\u pages%}
。检查一下,让我知道是的。谢谢,伙计。
$.each($("button"),function(){
  if(!$(this).text().trim()){
     $('this).hide();
  }
  else {
     $(this).show();
  }
});
if(!$('button').text()){
   $('button').hide();
}
else {
  $('button').show();
}