2012-05-11 59 views
0

HTML衝突的按鍵與jQuery。點擊

<form id="create-template" class="form" action="" method="post"> 
    <p class="_50"> 
     <label for="t-name">Template name</label> 
     <input type="text" name="t-name" class="required"/> 
    </p> 
    <p class="_100"> 
     <label for="t-html">Template HTML</label> 
     <textarea id="t-html" name="t-html" class="required" rows="10" cols="40"></textarea> 
    </p> 
    <div class="block-actions"> 
     <ul class="actions-left"> 
      <li><a class="button red" id="reset-template" href="javascript:void(0);">Clear</a></li> 
     </ul> 
     <ul class="actions-right"> 
      <li><div id="preview"><input type="submit" class="button" value="Preview template"></div></li> 
      <li><input type="submit" class="button" value="Create template"></li> 
     </ul> 
    </div> 
</form> 

的JavaScript:

$("#preview").click(function() { 
     $('#create-template').submit(function() { 
      window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars'); 
      this.target = 'formpopup'; 
     }); 
    }); 

當按下Preview template它會打開一個彈出窗口,並顯示模板的預覽。這是對的。

預覽模板後,按Create template頁面提交彈出。這是不正確的。

只有在預覽模板時纔會出現此問題。除非您預覽模板,否則Create template會在同一頁面上提交表格。

如何保持preview templatecreate template不衝突?

回答

0

這一行告訴表單提交到彈出窗口:

this.target = 'formpopup'; 

將其更改爲:

this.target = window.opener; 

你可能會想在提交後關閉彈出窗口。爲此,請添加以下行:

formpopup.close(); 
+0

當我刪除它或將其重命名爲「top」時,彈出窗口變爲空白。使用'top'也會打開一個新窗口。 :| – user1360107

+0

嘗試我的更新代碼 – bfavaretto

+0

謝謝你的嘗試,遺憾的是它仍然沒有像想象的那樣工作。對不起,它不起作用。 – user1360107