jQuery - 动态隐藏/显示对话框上的按钮



我有一个对话框 -

<div data-role="dialog" id="msg-popup">
  <div data-role="header">
      <h1>Notification</h1>
  </div>
  <div data-role="content" id> 
    <b id="notif-subject"></b>  
    <a href="#notif-details1" id:"show-notif" data-role="button">Show notification</a>
    <a href="#" data-rel="back" data-role="button">Cancel</a>
  </div> 
</div>

我想使用 jquery 代码动态隐藏和显示 show-notif 按钮。我该怎么做?

我试过了

$("#show-notif").hide(); 

这对我不起作用。有什么想法吗?

似乎有小的语法错误:

<a href="#notif-details1" id:"show-notif" data-role="button">Show notification</a>

它应该是(:替换为=):

<a href="#notif-details1" id="show-notif" data-role="button">Show notification</a>

这些函数应该可以工作:

$('#show-notif').hide();
$('#show-notif').show();

HTML 代码中的此行替换为

<a href="#notif-details1" id:"show-notif" data-role="button">Show notification</a>

<a href="#notif-details1" id="show-notif" data-role="button">Show notification</a>

因为你需要使用

id="show-notif"

JSFIDDLE 演示 : http://jsfiddle.net/MfQeF/

id:"show-notif"不是一个有效的语句。

它应该是 id="show-notif"

将Firefox(或Chrome)与html验证器或Web开发人员等插件一起使用。它可以显示语法错误。

最新更新