2009-09-11 69 views
0

此代码是模态确认从jQuery的现场演示:如何在jQuery中编辑对话框中的按钮动作?

<script type="text/javascript"> 
$(function() { 
    $("#dialog").dialog({ 
     bgiframe: true, 
     resizable: false, 
     height:140, 
     modal: true, 
     overlay: { 
      backgroundColor: '#000', 
      opacity: 0.5 
     }, 
     buttons: { 
      'Yes': function() { 
       $(this).dialog('close'); 
      }, 
      'No': function() { 
       $(this).dialog('close'); 
      } 
     } 
    }); 
}); 
</script> 



<div class="demo"> 

<div id="dialog" title="Empty the recycle bin?"> 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 

<!-- Sample page content to illustrate the layering of the dialog --> 
<div class="hiddenInViewSource" style="padding:20px;"> 
    <p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p> 
    <form> 
     <input value="text input" /><br /> 
     <input type="checkbox" />checkbox<br /> 
     <input type="radio" />radio<br /> 
     <select> 
      <option>select</option> 
     </select><br /><br /> 
     <textarea>textarea</textarea><br /> 
    </form> 
</div><!-- End sample page content --> 

</div><!-- End demo --> 

<div class="demo-description"> 

<p>Confirm an action that may be destructive or important. Set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p> 

</div><!-- End demo-description --> 

谁能告诉我如何修改按钮的动作?当点击“是”时,我想要重定向到test.php,当我点击“否”时,我想要重定向到另一页。

回答

1

如何挂钩到两个按钮应该是显而易见的,所以我假设你的实际问题是“你如何使用javascript重定向”。具体方法如下:

window.location = "http://something.com/foo" 

如果你不知道在哪里把这个片段中,看了你的代码出声,你会弄明白。

+0

这就是我的意思。对不起,我是一个小菜鸟。谢谢! – noob 2009-09-11 19:59:47

+0

既然你是新来的人:如果我的帖子回答了你的问题,请点击它上面的“已答复”复选标记,以便它被标记为已接受。 – 2009-09-11 20:03:57

+0

另一个问题我怎样才能整合这个按钮?我的意思是当我运行这个代码时,对话框自动出现。我怎么才能让它出现后只有按下按钮? – noob 2009-09-11 20:05:09

相关问题